The #python str.format method is used for formatted output of strings.

The #python str.format method is used for formatted output of strings. 
#''.format()
print('{0}+{1}={2}'.format(1,2,3))
#1+2=3 The numbers in the curly brackets in the visible string correspond to Several parameters of format.
print('{}+{}={}'.format(1,2,3))
#1+2=3 If you omit the number, you can get the same output. But the replacement order is by default [0],[1],[2]... .
#
print('{1}+{0}={2}'.format(1,2,3))
#2+1=3 If {0} and {1} are replaced, the result is the same.
print('{0}\tLOVE\t{1}'.format('I','YOU !'))
#I LOVE YOU ! Output string
name='xiaoming'
age=23
print('{0}\ tis\t{1}\tyears old this year !'.format(name,age))
#xiaoming is 23 years old this year !
print('{0:.4}'.format(1/6))
#0.1667 Decimal point precision matches to 4 digits
print('{0:8}:{1:8}'.format('name','xiaoming'


print('{0:<7.3}..'.format(1/3))
#0.333 .. #Fine width control (left in width), similarly '>' is right, '^' is center. Symbols are vivid.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324382600&siteId=291194637