一、安装:
pip install prettytable
二、实例:
from prettytable import PrettyTable
table = PrettyTable()
table.field_names = ["学号", "姓名", "语文", "数学", "英语", "物理", "化学", "总分", "平均分"]
table.add_row(["20170001", "张三", 85, 92, 78, 88, 90, 513, 64.13])
table.add_row(["20170002", "李四", 75, 80, 85, 90, 78, 508, 63.5])
table.add_row(["20170003", "王五", 90, 95, 92, 88, 85, 550, 68.75])
print(table)
三、输出:
+----------+------+------+------+------+------+------+------+--------+
| 学号 | 姓名 | 语文 | 数学 | 英语 | 物理 | 化学 | 总分 | 平均分 |
+----------+------+------+------+------+------+------+------+--------+
| 20170001 | 张三 | 85 | 92 | 78 | 88 | 90 | 513 | 64.13 |
| 20170002 | 李四 | 75 | 80 | 85 | 90 | 78 | 508 | 63.5 |
| 20170003 | 王五 | 90 | 95 | 92 | 88 | 85 | 550 | 68.75 |
+----------+------+------+------+------+------+------+------+--------+