Python 以指定宽度格式化输出

当对一组数据输出的时候,我们有时需要输出以指定宽度,来使数据更清晰。这时我们可以用format来进行约束

mat = "{:20}	{:28}	{:32}"
print(mat.format("占4个长度","占8个长度", "占12长度"))
#如果需要居中输出在宽度前面加一个^
mat = "{:^20}	{:^28}	{:^32}"
print(mat.format("占4个长度","占8个长度", "占12长度"))

原文地址:https://www.cnblogs.com/sea-stream/p/10231989.html