In python3 you can use the format method from string:

print("{:^10.2f}|{:^10.2f}|{:^10.2f}|{:^10.2f}|".format(x,sin(x),cos(x),tan(x)))

Notice that ^ means to center, 10 is the total size of the 'cell' and .2f is to print a float with 2 decimal places, change it according to your needs.

Answer from DSLima90 on Stack Overflow
🌐
Reddit
reddit.com › r/learnprogramming › help: python list to table (without module import)
r/learnprogramming on Reddit: Help: Python list to table (without module import)
November 25, 2019 -

Without using any modules or imports, how can I take the below list and print it as a table?

['Southwest', '0', '0', '0', '0', 'Yes!', 'JetBlue', '20', '35', '75', '125', 'Yikes', 'Alaska Airlines', '25', '25', '125', '155', 'Ooof', 'Delta', '25', '35', '200', '150', 'We Lost Track', 'United', '25', '35', '200', '250', 'Whaaaaat?', 'Am. Airlines', '25', '35', '200', '205', 'Arrrgh!', 'Spirit', '30', '40', '100', '292', 'Really??']

image example of final output:

https://i.ibb.co/zVrmT7v/Screen-Shot-2019-11-24-at-7-35-55-PM.png

Discussions

python Printing a list in a tabular format without modules - Stack Overflow
I have a list called entryList which begins empty, but as the user is prompted for input this input is added to the list. After 2 runs the list will look something like this: [2, 1234, 'E', 2.0, 2.... More on stackoverflow.com
🌐 stackoverflow.com
python - Printing Lists as Tabular Data - Stack Overflow
The following function will create the requested table (with or without numpy) with Python 3 (maybe also Python 2). I have chosen to set the width of each column to match that of the longest team name. You could modify it if you wanted to use the length of the team name for each column, but will be more complicated. Note: For a direct equivalent in Python 2 you could replace the zip with izip from itertools. def print... More on stackoverflow.com
🌐 stackoverflow.com
How do I print a table in python while keeping appopriate space between each element ?
if you want to do this manually: 1 - find out the length of the longest element for each index 2 - when printing pad each value to the right with as many extra spaces as required or if you want to use a library - prettytable More on reddit.com
🌐 r/learnpython
8
1
April 6, 2022
printing table in format without using a library, SQLite 3 python - Stack Overflow
6 Printing a properly formatted SQLite table in Python More on stackoverflow.com
🌐 stackoverflow.com
🌐
PyPI
pypi.org › project › tabulate
tabulate · PyPI
Pretty-print tabular data in Python, a library and a command-line utility. ... printing small tables without hassle: just one function call, formatting is guided by the data itself
🌐
Stack Overflow
stackoverflow.com › questions › 72421774 › python-printing-a-list-in-a-tabular-format-without-modules
python Printing a list in a tabular format without modules - Stack Overflow
values = [2, '1234', 'E', 2.0, 2.71, 6, '0800', 'U', 2.34, 20.89] cols = ["EntryNo", "PumpNo", "Time", "FType", "LPrice", "FAmount"] print(*cols) print("-" * len(" ".join(cols))) # optional for idx, i in enumerate(range(0, len(values), 5), start=1): print("{:<7d} {:<6d} {:<4s} {:<5s} {:<6.2f} {} ".format(idx, *values[i:i + 5])) EntryNo PumpNo Time FType LPrice FAmount ---------------------------------------- 1 2 1234 E 2.00 2.71 2 6 0800 U 2.34 20.89 · You can use pandas, you'll easily have an nice output, with to_markdown for example · import pandas as pd values = [2, '1234', 'E', 2.0, 2.71, 6, '0800', 'U', 2.34, 20.89] df = pd.DataFrame([[idx, *values[i:i + 5]] for idx, i in enumerate(range(0, len(values), 5), start=1)], columns=["EntryNo", "PumpNo", "Time", "FType", "LPrice", "FAmount"]) print(df.to_markdown(index=False))
Top answer
1 of 16
1042

There are some light and useful python packages for this purpose:

1. tabulate

https://pypi.python.org/pypi/tabulate

from tabulate import tabulate
print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
Name      Age
------  -----
Alice      24
Bob        19

tabulate has many options to specify headers and table format.

print(tabulate(
    [['Alice', 24], ['Bob', 19]],
    headers=['Name', 'Age'],
    tablefmt='orgtbl'))
| Name   |   Age |
|--------+-------|
| Alice  |    24 |
| Bob    |    19 |

2. PrettyTable

https://pypi.python.org/pypi/PrettyTable

from prettytable import PrettyTable
t = PrettyTable(['Name', 'Age'])
t.add_row(['Alice', 24])
t.add_row(['Bob', 19])
print(t)
+-------+-----+
|  Name | Age |
+-------+-----+
| Alice |  24 |
|  Bob  |  19 |
+-------+-----+

PrettyTable has options to read data from csv, html, sql database. Also you are able to select subset of data, sort table and change table styles.

3. texttable

https://pypi.python.org/pypi/texttable

from texttable import Texttable
t = Texttable()
t.add_rows([['Name', 'Age'], ['Alice', 24], ['Bob', 19]])
print(t.draw())
+-------+-----+
| Name  | Age |
+=======+=====+
| Alice | 24  |
+-------+-----+
| Bob   | 19  |
+-------+-----+

with texttable you can control horizontal/vertical align, border style and data types.

4. termtables

https://github.com/nschloe/termtables

import termtables as tt

string = tt.to_string(
    [["Alice", 24], ["Bob", 19]],
    header=["Name", "Age"],
    style=tt.styles.ascii_thin_double,
    # alignment="ll",
    # padding=(0, 1),
)
print(string)
+-------+-----+
| Name  | Age |
+=======+=====+
| Alice | 24  |
+-------+-----+
| Bob   | 19  |
+-------+-----+

with texttable you can control horizontal/vertical align, border style and data types.

Other options

  • terminaltables - Easily draw tables in terminal/console applications from a list of lists of strings. Supports multi-line rows.
  • asciitable can read and write a wide range of ASCII table formats via built-in Extension Reader Classes.
2 of 16
325

Some ad-hoc code:

row_format ="{:>15}" * (len(teams_list) + 1)
print(row_format.format("", *teams_list))
for team, row in zip(teams_list, data):
    print(row_format.format(team, *row))

This relies on str.format() and the Format Specification Mini-Language.

🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › python print table
Python Print Table | How can we Print Tables in Python with Examples?
June 28, 2023 - The best part is that you do not need to format each print statement whenever you add a new item to the dictionary or the List. There are several other ways as well that can be utilized to print tables in Python, namely: ... Otherwise, Pandas is another pretty solution if you are trying to print your data in the most optimized format.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
LearnPython.com
learnpython.com › blog › print-table-in-python
How to Pretty-Print Tables in Python | LearnPython.com
When you finish the exploratory data analysis phase, you may want to make your tables look nicer. Two libraries provide the functionality to pretty print comma-separated values (CSV) in Python: tabulate and prettytable.
🌐
Reddit
reddit.com › r/learnpython › how do i print a table in python while keeping appopriate space between each element ?
r/learnpython on Reddit: How do I print a table in python while keeping appopriate space between each element ?
April 6, 2022 -

Hey, i'm a beginner in python and it's been only couple of weeks since i've been into the world of coding. What I want to do is to print a table, by a table I mean a list that contains sublists and I want them to be printed in a form of a table, when printing it using the following code :

for i in range(n+1):
    print(*lst[i],end='')
    print()

The printed table looks like :

1 2 89 92
4 56 84 144
1 5 0 6
6 63 173 242

My concern here is that I want it to be printed in a more organized way, so that it would like :

1  2   89   92
4  56  84   144
1  5   0    6
6  63  173  242

Any help will be appreciated ! Thanks in advance !

Find elsewhere
Top answer
1 of 3
3

Use the string formatting capability:

formatted_row = '{:<10} {:<6} {:>6} {:>6} {:<9} {:<9}'
print(formatted_row.format("Name", "Gender", "Age", "Score", "Date", "Time"))
for Row in Data:
    print(formatted_row.format(*Row))

Output:

Name       Gender    Age  Score Date      Time     
HAMMAD     MALE       18    900 07/01/18  13:07:02 
HAMMAD     MALE       18    850 07/01/18  13:30:11 
INDERVEER  MALE       18    750 07/01/18  13:35:46 
HAMMAD     MALE       18    500 07/01/18  13:08:29 
HAMMAD     MALE       18    400 07/01/18  14:07:29 
PARSA      MALE       18    300 07/01/18  13:36:58 
HADIA      FEMALE     19    300 07/01/18  14:09:37 
MANAAL     FEMALE     18    100 07/01/18  13:51:40 
...

Note

In this approach, we hard-code the width of the columns. In order to dynamically adjust the columns width, we will have to do a good deal more works. I hope this will work for you.

Update

In order to dynamically adjust the widths, we need to pass through the data twice: The first time to determine the maximum width for each column, and the second to print.

# Determine the longest width for each column
header = ("Name", "Gender", "Age", "Score", "Date", "Time")
widths = [len(cell) for cell in header]
for row in Data:
    for i, cell in enumerate(row):
        widths[i] = max(len(str(cell)), widths[i])

# Construct formatted row like before
formatted_row = ' '.join('{:%d}' % width for width in widths)

print('DEBUG: widths={!r}'.format(widths))
print('DEBUG: formatted_row={!r}'.format(formatted_row))

print(formatted_row.format(*header))
for row in Data:
    print(formatted_row.format(*row))

Output:

DEBUG: widths=[9, 6, 3, 5, 8, 8]
DEBUG: formatted_row='{:9} {:6} {:3} {:5} {:8} {:8}'
Name      Gender Age Score Date     Time    
HAMMAD    MALE    18   900 07/01/18 13:07:02
HAMMAD    MALE    18   850 07/01/18 13:30:11
INDERVEER MALE    18   750 07/01/18 13:35:46
...

Once you are happy with the result, you can delete the DEBUG lines. They are there to show how the code works.

2 of 3
0

For the heading, just select the text you want, like

select 'Name    Gender    Age  ...';

To format the data, use the printf() function (see https://sqlite.org/lang_corefunc.html#printf), like

select printf('%-20s %-6s  %2d ....', Name, Gender, Age, ...) from ...;

(Adjust as necessary.)

🌐
DataCamp
datacamp.com › tutorial › python-tabulate
Python Tabulate: A Full Guide | DataCamp
September 5, 2024 - Tabulate provides a command-line utility for generating tables directly from the terminal without writing the whole Python code. ... 322.5KContinue to build your modern Data Science skills by learning about iterators and list comprehensions. ... 470.6KLearn the art of writing your own functions ...
🌐
Enkle Designs
enkledesigns.com › home › how can i print a table in python?
How Can I Print a Table in Python?
September 16, 2025 - What is the `tabulate` library and how does it help in printing tables? `tabulate` is a third-party Python library that formats lists or dictionaries into well-structured tables with various styles, making it easy to print readable tables without manual formatting.
🌐
DevGenius
blog.devgenius.io › how-to-easily-print-and-format-tables-in-python-18bbe2e59f5f
How To Easily Print and Format Tables in Python | by Khuong Lân Cao Thai | Dev Genius
July 26, 2022 - How To Easily Print and Format Tables in Python Let’s see how to do this in a quick and simple way. I have worked with Microsoft Excel since I started my career. I can’t count the number of …
🌐
Reddit
reddit.com › r/learnpython › how to make a table without additional libraries
r/learnpython on Reddit: How to make a table without additional libraries
March 22, 2023 -

#Task 3 loan calc

principal=250000
interest_rate=0.04
monthly_payment=1000
payment_by_month=1000
balance=250000
length_of_loan=0
total_paid=0


while balance > 0:
    interest = balance * (interest_rate/12)
    print(interest)
    new_balance = balance + interest
    if new_balance < 500:
        payment_by_month = new_balance
        last_month_payment = payment_by_month
    balance = new_balance - payment_by_month
    length_of_loan+=1
    total_paid+= payment_by_month
    if balance < 1:
        print(length_of_loan)
    print(balance)    

print(total_paid)

So i've got this loan calculator that calculates the monthly payment, interest, new balance, etc for each month until the balance reaches 0, for the assignment I'm doing I need all of this displayed in a table with the months on the left and I am not allowed to use df from pandas or anything like that. Does anyone know how I would go about doing this, also while the actual computed values can't be rounded the table must be rounded to two decimal places. The table needs to have months, payment, interest, and balance.

🌐
YouTube
youtube.com › watch
Python Tutorial - Importing CSV Printing Table (No modules) Part 2 - YouTube
How to view our data in a human friendly format that we imported from a CSV file. In this video I show you how you can use basic python to view the data in a...
Published: September 16, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › printing-lists-as-tabular-data-in-python
Printing Lists as Tabular Data in Python - GeeksforGeeks
April 20, 2025 - Let us consider an example: Python # A python code without pprint import requests def geocode · 2 min read Print Single and Multiple variable in Python · In Python, printing single and multiple variables refers to displaying the values stored in one or more variables using the print() function.Let's look at ways how we can print variables in Python:Printing a Single Variable in PythonThe simplest form of output is displaying the value of a single var · 2 min read Matplotlib.axes.Axes.add_table() in Python
🌐
Educative
educative.io › answers › print-a-table-in-python
Print a table in python
June 27, 2026 - It is always a good idea to nicely format the output of your program to make it easier to understand and interpret. Following this principle, Python lists can be displayed in the form of a table.
🌐
Readthedocs
tableprint.readthedocs.io
Tableprint — Tableprint 0.8.0 documentation
You can use it to print single rows of data at a time (useful for printing ongoing computation results). ... Tableprint offers two functions that print a table directly, tableprint.table and tableprint.dataframe. The first takes a numpy array and a list of headers, whereas the second takes a pandas DataFrame as input.
🌐
TutorialsPoint
tutorialspoint.com › printing-lists-as-tabular-data-in-python
Printing Lists as Tabular Data in Python
The simplest approach uses Python's built-in print() function with string formatting. This method works well for basic tables with uniform data ?
🌐
Reddit
reddit.com › r/learnpython › how to print data in a table format?
r/learnpython on Reddit: How to print data in a table format?
April 27, 2021 -

Hi Guys,

Please help me out, I am very weak in programming. I have the below code block which prints out all EC2 instances in an AWS account that are not of the latest generation along with the Cloudformation template used to provision them. The code is working fine now, it's just I need the output to be in a table. I tried using tabulate (commented out in the code block below) but the problem is it prints out and repeats the "headers" specified in each row instead of just on the very top, i think this is because of the whole thing is wrapped in for loop, not sure how I can work around it. I was told that the csv module maybe helpful but I looked python doc and it looks like that is for reading data from a .csv file and then processing it using the csv module. If you guyz can edit my code below and paste it here with the modification needed to display the data in a table format, I would be ever grateful to you. Please help me :( :( :(

import boto3
from tabulate import tabulate
 
ec2 = boto3.resource('ec2')
latestInstanceTypes = ['t3', 'm5', 'c5']

for instance in ec2.instances.all():
    if instance.instance_type.split('.')[0] not in latestInstanceTypes:
        stack_ids = [x['Value'] for x in instance.tags if x['Key'] == 'aws:cloudformation:stack-id']
        stack_id = stack_ids[0] if len(stack_ids) else None

        instance_names = [x['Value'] for x in instance.tags if x['Key'] == 'Name']
        instance_name = instance_names[0] if len(instance_names) else None
        #print(tabulate([[instance.id, instance.platform, instance.instance_type, instance.public_ip_address, instance.image.id, instance.state, stack_id]], headers=['Id', 'Platform', 'Type', 'Public IPv4', 'AMI', 'State', 'CF Template'], tablefmt='orgtbl'))
        print(
            "Id: {0}\nName: {1}\nType: {2}\nCFTemplate: {3}\nPlatform: {4}\nAMI: {5}\nState: {6}\n".format(
            instance.id, instance_name, instance.instance_type, stack_id, instance.platform, instance.image.id, instance.state
            )
        )
🌐
Brainly
brainly.com › computers and technology › high school › how to create a table in python without using the `tabulate` library
[FREE] How to create a table in Python without using the `tabulate` library - brainly.com
November 27, 2023 - To create a table in Python without the tabulate library, you can use string formatting methods, with list comprehensions to align and fix column width, resulting in a neatly printed table in the console.