打开Python的二维矩阵/列表到表矩阵、列表、Python

2023-09-07 12:56:33 作者:等待的滋味

我怎么能拒绝这样的:

students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)]

这个:

Abe     200

Lindsay 180

Rachel  215

编辑:这应该可以适用于任何大小的列表

This should be able to work for any size list.

推荐答案

使用字符串格式化:

>>> students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)]
>>> for a, b in students:
...     print '{:<7s} {}'.format(a, b)
...
Abe     200
Lindsay 180
Rachel  215
 
精彩推荐
图片推荐