Frequently used format notes for the python format function.
>>> #As many as the number of arguments{}write
>>> print("{}{}".format(12, 34))
1234
>>> #Specify the index of the argument
>>> print("{1}:{0}".format(12, 34))
34:12
>>> #Specify the number of digits(Filled with blanks)
>>> print("{1:4}:{0:3}".format(12, 34))
34: 12
>>> #Comma in the thousandth place
>>> print("{:,}".format(123456789))
123,456,789
>>> #Right justify by specifying the number of digits
>>> print("→{:>8}←".format(12))
→ 12←
>>> #Left justified by specifying the number of digits
>>> print("→{:<8}←".format(12))
→12 ←
>>> #Specify the number of decimal places
>>> print("{:>.4f}".format(12.456))
12.4560
>>> #Specify the total number of digits and the number of digits after the decimal point
>>> print("→{:>8.4f}←".format(12.456))
→ 12.4560←
>>> #Specifying characters to fill in the number of digits
>>> print("→{:!>8}←".format(12))
→!!!!!!12←
Recommended Posts