Python: formatted strings (fstrings) and format specification for str, int and float objects
Python can use str concatenation, fstrings, the str format method and the % operator to incorporate objects into a str. This video discusses the use of these and format specifiers for the str, int and float data types.
Written Notes:
https://dellwindowsreinstallationguide.com/python-fstrings/
rstring:
r"C:\Windows"
fstring:
f"{}" (the {} is used as a placeholder for an object)
f"{object}"
The colon : is used after the object to specify the formatting options. The abbreviations s, d and f are used to denote a str, int and a float.
f"{str_object:s}"
f"{int_object:d}"
f"{float_object:f}"
For a str the additional parameter n can can be used to specify the number of characters, the str should occupy.
f"{str_object:ns}"
An int also uses n but this can be prepended with 0 to display leading zeroes.
f"{int1:0nd}"
For the case of a float, one of the characters specified by n is the decimal point . n can be prefixed by 0 to display leading zeroes and suffixed by .m to specify the number of places after the decimal point.
f"{float1:0n.mf}"
In many cases only .m will be specified.
f"{float1:.mf}"