打开Python的二维矩阵/列表到表 [英] Turn the Python 2D matrix/list into a table

查看:428
本文介绍了打开Python的二维矩阵/列表到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能拒绝这样的:

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

这篇关于打开Python的二维矩阵/列表到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆