October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Print an Array in Python: A Step-by-Step Guide

Use print() for a Python list or NumPy array, then choose unpacking, pretty printing, or NumPy print options for the output you need.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a regular Python list, use print(my_array). If by “array” you mean a NumPy array or Python’s array.array, you can also print the object directly, but the displayed format differs. The examples below show how to identify the type you have and choose the output you want.

Print a Python list

Lists are the usual sequence beginners mean when they say “array.” Pass the list to print() to display its Python representation, including square brackets and commas:

my_array = [1, 2, 3, 4]
print(my_array)
# [1, 2, 3, 4]

Python’s built-in print() converts supplied objects to text and writes them to standard output by default. When you pass multiple objects, it puts a space between them unless you choose a different sep; it ends the output with a newline unless you change end. See the Python built-in functions documentation.

Print elements without the list brackets

Use the unpacking operator * to pass each list item to print() separately. Set sep to choose what appears between items:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
print(*my_array, sep=", ")
# 1, 2, 3, 4

For a label or a particular number format, build the text explicitly. This example formats numeric values to two decimal places:

print("Values:", ", ".join(f"{value:.2f}" for value in my_array))

The .2f format expects numbers; it is not a default format applied to every Python value.

Check which kind of array you have

Python has more than one object that may be called an array. Choose the display method based on the actual type:

Type What to do What to expect
Python list Use print(values), or print(*values, sep=", ") for separated items. The ordinary representation includes brackets and commas; unpacking prints the items separately.
array.array Print the object directly, or call .tolist() for a list representation. It is a standard-library sequence constrained to a type code. See the Python array documentation.
NumPy ndarray Use print(arr). NumPy lays out values according to the array’s dimensions; its display is not a conversion to nested Python lists. See the NumPy quickstart.

Display a NumPy array or matrix

Print a NumPy array directly. For example, a two-dimensional array displays as a matrix:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

arr = np.array([[1, 2], [3, 4]])
print(arr)
# [[1 2]
#  [3 4]]

NumPy’s display uses spaces between values rather than the commas shown in a Python list. One-dimensional arrays appear as rows; higher-dimensional arrays are grouped into slices. This is NumPy’s representation layout, not a change to the underlying array.

Make nested Python data easier to read

For nested built-in structures such as lists and dictionaries, use pprint.pp() when line breaks and indentation make the output easier to inspect:

from pprint import pp

nested = [[1, 2, 3], [4, 5, 6]]
pp(nested, width=20)

The pprint module keeps structures on one line when they fit and breaks them across lines when needed. Its width, indentation, depth, and compactness can be configured. It is intended for Python data structures; for ndarray display, adjust NumPy’s own print options instead. See the Python pprint documentation.

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

Control how NumPy formats large arrays and numbers

Show more or all elements

NumPy abbreviates large arrays with an ellipsis, showing edges rather than every value. The documented default summarization threshold is 1000 elements. To request the full representation, set a higher threshold, such as sys.maxsize:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import sys
import numpy as np

np.set_printoptions(threshold=sys.maxsize)
print(np.arange(10000))

Printing every element of a very large array can overwhelm a terminal or log. NumPy documents threshold and set_printoptions() in its API reference.

Limit displayed decimal places or suppress scientific notation

Use np.printoptions() as a context manager when you want a formatting override to apply only within a block:

with np.printoptions(precision=2, suppress=True):
    print(arr)

precision controls displayed floating-point precision, while suppress=True avoids scientific notation for small values. NumPy also offers settings for threshold, line width, representations of NaN and infinity, and type-specific formatters. These settings affect ndarray display, not the formatting of standalone scalar values. See the NumPy printing guide and the NumPy print-options reference.

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.

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

Leave a Reply

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

Free tools Windows power users keep installed

One-click scans. No signup required.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair 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.