Character string type typology format () method, basic usage format:
** .format (
Yuichi series tank composition, use restraint retouched character string skewer inset, current position, its basic idea, general format () methodical
>>> print("{}:{}:{}".format("1","2","3"))
1:2:3
>>> print("{2}:{1}:{0}".format("1","2","3"))
3:2:1
format () Method Medium Exclusion of tanks Comprehensive parameter introduction, can be reduced Comprehensive form restraint. At this time, the tank-like internal sample formula:
{
>>> s = "python"
>>> "{0:30}".format(s) #Import 1, Typographic alignment, Typographic alignment 30
'python '
>>> "{0:>30}".format(s) #Import 2, designated right opposite, 30 degrees
' python'
>>> "{0:<30}".format(s) #Import 3, designated left
'python '
>>> "{0:*^30}".format(s) #Import 4, in-house
'************python************'
>>> "{0:-^20,}".format(1234567890) #Import 1, Tadashi Ichigo, Comma display number Thousands delimiter
'---1,234,567,890----'
>>> "{0:-^20}".format(1234567890) #Import 2, contrast top surface, classified by
'-----1234567890-----'
>>> "{0:-^20,.2f}".format(123456.7890) #Import 3, posterior.2f Display decimal point precision
'-----123,456.79-----'
>>> "{0:b},{0:c},{0:d},{0:o},{0:x}".format(425) #Import, request Multi-type import exported integer
'110101001,Ʃ,425,651,1a9'
Opposite floating point number type, export type comprehensive 4 types:
Floating-point number Export time-out amount used <.Accuracy> Displayed decimal Partial degree, Arisuke in Favorable export rating formula.
>>> "{0:e},{0:E},{0:f},{0:%}".format(3.14)
'3.140000e+00,3.140000E+00,3.140000,314.000000%'
Note: Superficial {0: e}, etc., given in Japanese grammar str [1: 3]
character string skewer classification, caution classification
Recommended Posts