pip install
tabulate
from tabulate import tabulate
table = [
["Sun",696000,1989100000],
["Earth",6371,5973.6],
["Moon",1737,73.5],
["Mars",3390,641.85]
]
headers = ['planet', 'R(km)', 'mass']
print(tabulate(table, headers, tablefmt="grid"))
+----------+---------+---------------+
| planet | R(km) | mass |
+==========+=========+===============+
| Sun | 696000 | 1.9891e+09 |
+----------+---------+---------------+
| Earth | 6371 | 5973.6 |
+----------+---------+---------------+
| Moon | 1737 | 73.5 |
+----------+---------+---------------+
| Mars | 3390 | 641.85 |
+----------+---------+---------------+
Да и самостоятельно несложно реализовать:
num = 20
print('-'*num, '|'+'test'.center(num-2)+'|', '-'*num, sep='\n')
--------------------
| test |
--------------------