prettytable安装(推荐学习:Python视频教程)
pip install prettytable
示例
import prettytable as pt# tb = pt.prettytable( ["City name", "Area", "Population", "Annual Rainfall"])tb = pt.prettytable()tb.fIEld_names = ["City name", "Area", "Population", "Annual Rainfall"]tb.add_row(["AdelaIDe",1295, 1158259, 600.5])tb.add_row(["Brisbane",5905, 1857594, 1146.4])tb.add_row(["Darwin", 112, 120900, 1714.7])tb.add_row(["Hobart", 1357, 205556,619.5])print(tb)
输出:
+-----------+------+------------+-----------------+| City name | Area | Population | Annual Rainfall |+-----------+------+------------+-----------------+| AdelaIDe | 1295 | 1158259 | 600.5 || Brisbane | 5905 | 1857594 | 1146.4 || Darwin | 112 | 120900 | 1714.7 || Hobart | 1357 | 205556 | 619.5 |+-----------+------+------------+-----------------+
如果没有添加表头,那么会以默认的FIEld+编号显示,例如:
+---------+----------+----------+------------+| FIEld 1 | FIEld 2 | FIEld 3 | FIEld 4 |+---------+----------+----------+------------+
更多Python相关技术文章,请访问Python教程栏目进行学习! 总结
以上是内存溢出为你收集整理的python怎么输出表格全部内容,希望文章能够帮你解决python怎么输出表格所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)