Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

Print Lists in Python: Choose the Output You Need

Use print(items) for a list’s normal representation, or choose a loop, enumerate(), argument unpacking, or pprint for a different display.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use print(items) to display a list with its brackets and normal Python representation. To show one item per line, loop over the list; use enumerate() for numbered output, print(*items, sep=', ') for a separator without brackets, or pprint.pp() for nested data.

Print a whole list with its brackets

Pass the list to print() to show its normal representation:

As an Amazon Associate I earn from qualifying purchases.

colors = ['red', 'green', 'blue']
print(colors)

Output:

['red', 'green', 'blue']

The square brackets and quotes around strings are part of how Python represents the list; they do not mean those characters are stored as list elements. For ordinary built-in lists, str() and repr() often produce the same-looking display, though they have different aims: str() is intended to be fairly human-readable, while repr() is intended to be readable by the interpreter when possible. See the Python tutorial’s input and output documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Print each item on a new line

Iterate over the list and print each value separately:

for color in colors:
    print(color)

Each call to print() ends with a newline by default, so the values appear on separate lines. This also works for an empty list: the loop runs zero times and prints nothing.

Print a list without brackets

Use argument unpacking with a custom separator when you want one line of values without the list’s brackets:

print(*colors, sep=', ')

Output:

red, green, blue

The * passes the list elements as separate arguments to print(), and sep controls the text between those arguments. It does not change the list. If the list is empty, this call prints a blank line. The sep parameter separates arguments, not characters within a single string.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Print values with their positions

Use enumerate() when each item should be paired with its index:

for index, color in enumerate(colors):
    print(index, color)

By default, the index starts at zero. To number the output starting at one, provide a starting value:

for number, color in enumerate(colors, start=1):
    print(number, color)

Python’s tutorial documents enumerate() as a way to retrieve a sequence position and value together; see Data Structures.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Format nested or long lists

For nested data, pprint.pp() displays a readable representation and adds line breaks when the structure exceeds its configured width:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import pprint

pprint.pp([[1, 2], [3, 4]])

Use pprint.pprint() if you want to set options such as width or indentation explicitly. The Python 3.11.16 pprint documentation describes the module’s formatting behavior and options.

Common mistakes to avoid

  • Relying on a bare variable name in a script: entering colors by itself displays a value in an interactive session, but a script should call print(colors) when output is intended.
  • Expecting a different display from a list method: methods that mutate a list, such as colors.sort(), change the list and return None; they are not a way to print the changed list. Call print(colors) separately if you want to display it.
  • Assuming a set has list ordering: sets are unordered, unlike lists, so do not rely on a set’s display to preserve a sequence order.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.