我想用特定的对齐方式在一行中打印不同的变量。但是,str.format打印相同的字符串
Here is the code what i did and output
>>> print("{0:^20} {0:^20} {0:^40}\n".format('chkitem', 'Count', 'Coordinate'))
chkitem chkitem chkitem
我想打印
>>> print("{0:^20} {0:^20} {0:^40}\n".format('chkitem', 'Count', 'Coordinate'))
chkitem Count Coordinate
有什么问题
冒号前的零指定使用零索引格式参数,如果省略它们,将默认使用提供的下一个格式参数
您还可以指定
0:
、1:
、2:
等等,但最佳实践是,如果要多次打印参数,则只指定索引{0:^20}-0是项在格式参数中的位置。你必须增加它
相关问题 更多 >
编程相关推荐