Document Format
Document Format
When curly braces are empty, Python will do the substitution based on order of arguments
sent in format method. So in the above example the first pair of curly braces is replaced with
name, second pair with age and third pair with wt.
Can use the index numbers inside curly braces, to decide what goes where while substituting
values inside the string.
The value 0 refers to the first argument, 1 refers to the second argument and 2 refers to the
third argument.
This way you can change the order of the variables and you can use a data value even more
than once.
You can mix both positional and keyword arguments in the same string.
When using f conversion for values, you can limit the number of digits displayed
after the decimal point. This can be done by adding a dot followed by the number of
digits after the decimal you want to be displayed.
The float value will be rounded off, if it has more decimal places than the number of decimal
places we want to display.
You can use 0 if you don’t want any decimal places to be displayed.
By default strings are left justified in their width and numbers are right justified. To change
the justification you can use symbols < > ^
< for left justification
> for right justification
^ for centre justification
By default your output fields will be padded using spaces, if you want a character to be used
for padding then you can place it just after the colon, before the alignment specifier. It is the
character that is used to display data when the data is too small to fit in the assigned field
width. It is called fill character and it can be any character except '{' or '}'. The alignment
specifier should be provided if you want to specify a padding character.
s - For a string
Integers -
b for binary,
d for decimal base 10 notation,
x or X for hexadecimal
o for octal notation
Floating point -
e or E for exponential notation
f for fixed point notation
For more information on % style formatting, string format method and f strings please check
the following links on python.org.
https://docs.python.org/3/library/stdtypes.html#old-string-formatting
https://docs.python.org/3/library/string.html#formatstrings
https://docs.python.org/3/reference/lexical_analysis.html#f-strings