str.format() is making your fields left aligned within the available space. Use alignment specifiers to change the alignment:

'<' Forces the field to be left-aligned within the available space (this is the default for most objects).

'>' Forces the field to be right-aligned within the available space (this is the default for numbers).

'=' Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form ‘+000000120’. This alignment option is only valid for numeric types.

'^' Forces the field to be centered within the available space.

Here's an example (with both left and right alignments):

>>> for args in (('apple', '$1.09', '80'), ('truffle', '$58.01', '2')):
...     print '{0:<10} {1:>8} {2:>8}'.format(*args)
...
apple         $1.09       80
truffle      $58.01        2
Answer from Steven Rumbalski on Stack Overflow
Discussions

Trying to format a string into columns with python - Stack Overflow
I am trying to format a string to display two columns for a high score table. Python is able to do this well when using print · print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x) but when trying to use a formatted string, but becomes more challenging it seems. This is the result I am trying to get: #for name, score in list... More on stackoverflow.com
🌐 stackoverflow.com
python - How to print a list more nicely? - Stack Overflow
This is similar to How to print a list in Python “nicely”, but I would like to print the list even more nicely -- without the brackets and apostrophes and commas, and even better in columns. fooli... More on stackoverflow.com
🌐 stackoverflow.com
How do you print columns in python.
I'm not exactly sure what you're asking, but you can use string formatting to line up output. The "<" means left justified, the "10" means it will reserve 10 spaces for that string so anything printed next will print on the 11th spot. print("{:<10}".format(list[counter])) More on reddit.com
🌐 r/learnprogramming
9
1
November 30, 2018
python - How to format into columns from a list using a function? - Stack Overflow
At the moment I have a list that is being found from a text document and is being searched with a for loop: for sublist in mylist: if sublist[2] == inp: print (formatting(sublist)) ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
PyPI
pypi.org › project › columnize
columnize · PyPI
This is a Python module to format a simple (i.e. not nested) list into aligned columns. A string with embedded newline characters is returned.
Top answer
1 of 16
35

This answer uses the same method in the answer by @Aaron Digulla, with slightly more pythonic syntax. It might make some of the above answers easier to understand.

>>> for a,b,c in zip(foolist[::3],foolist[1::3],foolist[2::3]):
>>>     print '{:<30}{:<30}{:<}'.format(a,b,c)

exiv2-devel                   mingw-libs                    tcltk-demos
fcgi                          netcdf                        pdcurses-devel
msvcrt                        gdal-grass                    iconv
qgis-devel                    qgis1.1                       php_mapscript

This can be easily adapt to any number of columns or variable columns, which would lead to something like the answer by @gnibbler. The spacing can be adjusted for screen width.


Update: Explanation as requested.

Indexing

foolist[::3] selects every third element of foolist. foolist[1::3] selects every third element, starting at the second element ('1' because python uses zero-indexing).

In [2]: bar = [1,2,3,4,5,6,7,8,9]
In [3]: bar[::3]
Out[3]: [1, 4, 7]

zip

Zipping lists (or other iterables) generates tuples of the elements of the the lists. For example:

In [5]: zip([1,2,3],['a','b','c'],['x','y','z'])
Out[5]: [(1, 'a', 'x'), (2, 'b', 'y'), (3, 'c', 'z')]

together

Putting these ideas together we get our solution:

for a,b,c in zip(foolist[::3],foolist[1::3],foolist[2::3]):

Here we first generate three "slices" of foolist, each indexed by every-third-element and offset by one. Individually they each contain only a third of the list. Now when we zip these slices and iterate, each iteration gives us three elements of foolist.

Which is what we wanted:

In [11]: for a,b,c in zip(foolist[::3],foolist[1::3],foolist[2::3]):
   ....:      print a,b,c                           
Out[11]: exiv2-devel mingw-libs tcltk-demos
         fcgi netcdf pdcurses-devel
        [etc]

Instead of:

In [12]: for a in foolist: 
   ....:     print a
Out[12]: exiv2-devel
         mingw-libs
         [etc]
2 of 16
34

Although not designed for it, the standard-library module in Python 3 cmd has a utility for printing a list of strings in multiple columns

import cmd
cli = cmd.Cmd()
cli.columnize(foolist, displaywidth=40)

Output:

exiv2-devel     msvcrt       
mingw-libs      gdal-grass   
tcltk-demos     iconv        
fcgi            qgis-devel   
netcdf          qgis1.1      
pdcurses-devel  php_mapscript

You even then have the option of specifying the output location, with cmd.Cmd(stdout=my_stream)

🌐
Delft Stack
delftstack.com › home › howto › python › python print column alignment
How to Print With Column Alignment in Python | Delft Stack
February 22, 2025 - For basic text formatting, format() or f-strings are the best options. For structured tabular data, tabulate and pandas provide automated formatting that ensures consistent alignment.
Find elsewhere
🌐
SQLPad
sqlpad.io › tutorial › python-formatted-output
Python formatted output | SQLPad
April 29, 2024 - When working with collections such as lists, tuples, and dictionaries in Python, formatting output becomes a bit more complex, but also more powerful. Properly displaying these data structures is vital for both debugging and presenting information in a readable way. Let's dive into some practical ways to format these collections. Lists and tuples can be formatted by converting them into strings or by formatting each individual element.
🌐
Scientifically Sound
scientificallysound.org › 2016 › 10 › 17 › python-print3
Take control of your Python print() statements: part 3 | Scientifically Sound
November 17, 2021 - In the last post, we learned how to control the precision of the number we print as well as the number of spaces these numbers take up. The last thing we need to learn to output nice data tables is how to align text and numbers when we use .format(). Aligning text and numbers with…
🌐
Medium
chrimaho.medium.com › print-python-lists-in-columns-bb6376cc8dbf
Print Python Lists in Columns: Better utilise the space in your Console | by Chris Mahoney | Medium
February 24, 2025 - This list_columns() function is a very useful tool to have in your Python toolbox. It allows you to output your lists in a column format, which is very useful when you have a long list of strings that you want to output in a more readable format.
🌐
YouTube
youtube.com › brad yourth
f-strings and column control - YouTube
Demonstrates f-strings for formatting columns with specified widths, alignment, and decimals.
Published: December 20, 2020
Views: 2K
🌐
Reddit
reddit.com › r/learnprogramming › how do you print columns in python.
r/learnprogramming on Reddit: How do you print columns in python.
November 30, 2018 -

I'm printing a large amount of lists containing 4 items in columns but I can't get them to line up. Does anyone know how to do this?

small sample of output:
Aaila	Aaliya	Aamna	Aamnaha                            
Aanya	Aarilynn	Aarna	Aarushi
Aasiyah	Aaya	Abagayle	Abang
Abay	Abbagayle	Abbegael	Abbegail
Abbeygail	Abbeygayle	Abbigael	Abbigale
Abbigrace	Abbygael	Abeam	Abeeha
Abeera	Abeg	Abey	Abi
Abighail	Abinash	Aboul	Abrar
Abree	Abriana	Abrianna	Abrieanna
Abriel	Abriella	Abrielle	Abual

🌐
Bobby Hadz
bobbyhadz.com › blog › python-print-list-in-columns
How to Print a List in Columns in Python | bobbyhadz
We specified the step value to get a list containing every 3 elements because we want to print 3 columns. The first list slice contains every 3 elements of the original list starting at index 0. The second list slice contains every 3 elements of the original list starting at index 1. The last step is to use a formatted string literal to format the list items in columns.
🌐
Blogger
knowledgestockpile.blogspot.com › 2011 › 01 › string-formatting-in-python_09.html
knowledge stockpile: String formatting in Python
September 1, 2011 - Keep reading to find out about ... basic formatting of the output produced using print statements. Specifically, below I discuss: how to set the column width of the column in which the output is printed; ... some other examples that illustrate output of numbers with thousand separator commas, output of numbers as percentages etc. Not all possibilities are discussed below. For more information, see http://www.python.org/dev/peps/pep-3101/ Suppose you have a list of tuples ...
🌐
Stack Overflow
stackoverflow.com › questions › 27191072 › how-to-format-into-columns-from-a-list-using-a-function
python - How to format into columns from a list using a function? - Stack Overflow
I can only imagine that is taking the value from the first of each entity in the list and appending it. instead of appending the whole word. ... The number before 's' is the width of the column in characters, and the string you wish to print is space-padded to that width.
🌐
ProjectPro
projectpro.io › recipes › format-string-in-pandas-dataframe-column
How to format string in a Pandas DataFrame Column? -
January 19, 2023 - This python source code does the following : 1. Creates a pandas series 2. Converts strings into lower and upper format 3. performs splits and capitalization · So this is the recipe on how we can format string in a Pandas DataFrame Column. Get Closer To Your Dream of Becoming a Data Scientist with 70+ Solved End-to-End ML Projects ... We have imported one library that is pandas which is only need for this. We have created a list ...
🌐
Bentley
cissandbox.bentley.edu › sandbox › wp-content › uploads › 2022-02-10-Documentation-on-f-strings-Updated.pdf pdf
A Guide to Formatting with f-strings in Python - CIS Sandbox
Program output is often required to be in tabular form. f-strings are very useful in formatting · this kind of output. The following lines produce a tidily aligned set of columns with integers and
🌐
Talkerscode
talkerscode.com › howto › python-formatting-output-into-columns.php
Python Formatting Output Into Columns
July 1, 2023 - The string variety has some styles that carry out applicable operations for filling strings to a presented column range. The operator can similarly exist operated for string formatting. It interprets the left explanation considerably like a printf()- style format as in C language strings to exist referred to the right argument. In Python, there’s no printf() function but the functionality of the long-lived printf is held in Python.
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.7 documentation
The example also prints percentage ... (see Format specification mini-language for details). Finally, you can do all the string handling yourself by using string slicing and concatenation operations to create any layout you can imagine. The string type has some methods that perform useful operations for padding strings to a given column ...