下面介紹一個快速制作ASCII表格庫——prettytable,可以方便地制作簡單表格。
1 安裝prettytable
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple prettytable
結果如下:
2 代碼實例
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)
結果如下: