Python格式化输出时动态指定长度
2021-05-11 22:00:31
print打印为了更加美观,可以指定长度
```
{:5} 固定5个字符,从最左边开始
{:^5} 固定5个字符,居中
```
示例代码
```
numbers = ["9787111544937", "9787111128069"]
names = ["深入理解计算机系统", "C程序设计语言"]
print("{:20}{}".format("ISBN", "书名"))
for i in range(len(numbers)):
print("{:20}{}".format(numbers[i], names[i]))
```
效果如下图
