另一种方法是使用tabulate。
首先,您需要导入它。在网上搜索如何导入。
如果您像我一样使用Spyder,则在Anaconda的命令窗口中,只需键入:
conda install -c conda-forge tabulate
这非常有用!
table = [["X Coordinate", "Y Coordinate", "Result"], [00, 00, 00], [00, 00, 00], [00, 00, 00]]
print(tabulate(table))
这将产生以下结果:
X Coordinate Y Coordinate Result
0 0 0
0 0 0
0 0 0
或者你可以这样做:
table = [[00, 00, 00], [00, 00, 00], [00, 00, 00]]
print(tabulate(table, headers=["X Coordinate", "Y Coordinate", "Result"]))
这将产生以下结果:
X Coordinate Y Coordinate Result
-------------- -------------- --------
0 0 0
0 0 0
0 0 0
如果您不喜欢破折号,您可以使用这个替代方案:
print(tabulate(table, tablefmt="plain"))
然后将会产生以下结果:
X Coordinate Y Coordinate Result
0 0 0
0 0 0
0 0 0