% Method (Old Method)
The %s and %r can both be used as placeholders for string. %s uses str()
for conversion while %r uses repr()
for conversion
Floating points numbers can be formatted using the %5.2f syntax. The 5 here represents the minimum number of characters to be present in the string the .2 refers to the number of digits after the decimal point
format() Method (New Method)
{}
is used as placeholder for the location where the variable needs to be substituted
We can additionally also specify the minimum string length, padding, number system and alignment of the variable using this method
F-Strings (String Interpolation)
We specify the variable that needs to be used along with its formatting inside the {} placeholder these strings always start with f
All the formatting that can be performed on the string using the format() method can be used in f-strings as well
For using {}
in the string it needs to be doubled {{}}
Python String Formatting Best Practices – Real Python