使用.format()方法槽 {}
1、"{}:计算机{}的cpu占用率为{}%".format("2018-10-10","c",10)槽与数字是一一对应的
>>> print("{}:计算机{}的cpu占用率为{}%".format("2018-10-10","c",10))
2018-10-10:计算机c的cpu占用率为10%
>>> print("{1}:计算机{0}的cpu占用率为{2}%".format("2018-10-10","c",10))
c:计算机2018-10-10的cpu占用率为10%
槽中如果有数字表示与后面的相连接
2、: 引导符号
<填充> 用于填充单个字符
<对齐> <左对齐 >右对齐 ^居中对齐
<宽度>槽设定的输出宽度
str="python"
>>> print("{0:a>20}".format(str))
aaaaaaaaaaaaaapython
>>> str="python"
>>> print("{0:a<20}".format(str))
pythonaaaaaaaaaaaaaa
str="python"
>>> print("{0:=^20}".format(str))
=======python=======
<,>数字的千位分隔符
<.>浮点数小数精度或字符串最大输出长度
<类型> 整数类型b,c,d,o,x,X浮点数类型e,E,f,%
print("{0:,.2f}".format(12345.6789))
12,345.68
>>> print("{0:.2f}".format(12345.6789))
12345.68
>>> print("{0:,}".format(12345.6789))
12,345.6789
print("{0:b},{0:c},{0:d}.{0:o},{0:x},{0:X}".format(425))
110101001,Ʃ,425.651,1a9,1A9