Answer the question
In order to leave comments, you need to log in
Python how to pack text into a square shape?
Hello everyone, how can I pack the text of the test type into a square shape:
+---------+
| test |
+---------+
Answer the question
In order to leave comments, you need to log in
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 |
--------------------
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question