October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Print a Dictionary in Python

Use print(my_dict) for a quick display, pprint.pp() for nested data, or iterate over .items() to print each key and value on its own line.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use print(my_dict) to display a Python dictionary. For nested or wide dictionaries, use pprint.pp(my_dict); to put each key and value on its own line, loop through my_dict.items().

Print a dictionary with print()

Pass the dictionary to Python’s built-in print() function:

person = {"name": "Ada", "age": 36}
print(person)

Output:

{'name': 'Ada', 'age': 36}

The braces and key:value pairs are Python’s representation of the dictionary; this output is not JSON. At an interactive Python prompt, you can also type the dictionary variable by itself to display its representation. Python’s documentation distinguishes str(), intended to be fairly human-readable, from repr(), intended to be interpreter-readable; for dictionaries and many other containers, they look the same. Python input and output documentation

Print each key and value on a new line

Use .items() to iterate over key-value pairs, then format each pair as needed:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
for key, value in person.items():
    print(f"{key}: {value}")

Output:

name: Ada
age: 36

This approach is useful when you want to label values, filter entries, or customize their display. A dictionary contains unique keys paired with values. Python data structures documentation

Pretty-print a nested or long dictionary

For nested data or a long display, Python’s standard-library pprint module formats structures across lines and indents them. Import it, then call pprint.pp():

import pprint

person = {
    "name": "Ada",
    "details": {"age": 36, "role": "developer"}
}
pprint.pp(person)

The pretty-printer keeps a structure on one line when it fits and wraps it to the available width when necessary. You can set that width explicitly:

pprint.pp(person, width=40)

The pprint.pp() default shown in the Python 3.14 documentation is sort_dicts=False, so dictionary entries are not alphabetically reordered by the pretty-printer. Python 3.14 pprint reference

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Print dictionary keys in alphabetical order

Dictionaries preserve insertion order in current Python; that is the order in which keys were added, not necessarily alphabetical order. The language reference documents insertion-order preservation as guaranteed since Python 3.7. Python built-in types documentation

To display entries alphabetically by key, iterate over sorted(person):

for key in sorted(person):
    print(f"{key}: {person[key]}")

Alternatively, ask pprint to sort dictionary keys:

pprint.pp(person, sort_dicts=True)

In the Python 3.14 reference, pprint.pp() defaults to sort_dicts=False, while pprint.pprint() defaults to sort_dicts=True. Set the option explicitly when the display order matters, rather than relying on different function defaults. Python 3.14 pprint reference

Choose the display method

Need Method What it does
Quick inspection print(d) Displays the dictionary’s string representation.
Nested or long structure pprint.pp(d) Indents and wraps the formatted structure; width can be configured.
One pair per line or custom formatting for k, v in d.items() Lets you label, filter, or format each key-value pair.
Alphabetical keys sorted(d) or pprint.pp(d, sort_dicts=True) Sorts keys for display rather than changing the dictionary’s insertion 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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
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.