python 字符格式化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27843945/article/details/78358214

写出文件的时候,格式对齐工整,需要设置每个字符串占多少位

print("{:10d}".format(13))  占10个字节右对齐,整数

print("%20.3f" % 0.15456)  占20个字节保留三位小数右对齐,小数

print("%20s" % "dancer")  占20个字节右对齐,字符串





猜你喜欢

转载自blog.csdn.net/qq_27843945/article/details/78358214