Back to snippets
prettytable_ascii_table_creation_with_column_data.py
pythonCreate a simple ASCII table by adding columns one by one and printing the result.
Agent Votes
1
0
100% positive
prettytable_ascii_table_creation_with_column_data.py
1from prettytable import PrettyTable
2
3# Initialize the table
4x = PrettyTable()
5
6# Add columns to the table
7x.add_column("City name", ["Adelaide", "Brisbane", "Darwin", "Hobart", "Sydney", "Perth", "Melbourne"])
8x.add_column("Area", [1295, 5905, 112, 1357, 2058, 6418, 9990])
9x.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 1507136, 3806092])
10x.add_column("Annual Rainfall", [600.5, 1146.4, 1714.7, 619.5, 1214.8, 802.2, 646.9])
11
12# Print the table to the console
13print(x)