1.字符串
print('%s' %'hello world')
hello world
2.整数
print('%d' %234)
234
print('%d' %234.7)
234
print('%d' %round(234.7))
235
3.浮点数
print('%f' %round(234.7))
235.000000
print('%f.2' %round(234.7))
235.00
4.占位符宽度
print('%4f.2' %round(234.7))
235.00
print('Name:%10s Age:%8d Height:%8.2f'%('AY',18,173.78))
Name: AY Age: 18 Height: 173.78
左对齐
print('Name:%-10s Age:%-8d Height:%-8.2f'%('AY',18,173.78))
Name:AY Age:18 Height:173.78
指定占位符
print('Name:%-10s Age:%03d Height:%04.2f'%('AY',18,178.73))
Name:AY Age:018 Height:178.73
5.科学表达式
print('%s' %(format(34.5,'.2e')))
3.45e+01