Skip to the workspace
Pebellslearn by building

Python syntax & reference

Find the form you need, compare how it behaves, and open the complete explanation when you need more depth.

Python 3.10+ syntax; individual entries identify newer features. Browser exercises use the configured Python runner.

1 matching syntax entry

Dictionary lookup and iteration

Learn in depth →

A dictionary maps hashable keys to values and preserves insertion order.

mapping[key]; mapping.get(key, default); mapping.items()

Example

counts = {"tea": 2}
print(counts.get("coffee", 0))
for name, count in counts.items():
    print(name, count)

Result

0
tea 2

Watch for: [] raises KeyError for a missing key. get does not insert its default. setdefault may insert it.

Practise this topic →
Complete explanation index (91 lessons indexed)

Dictionaries

Technical sources and review date

Original Pebells examples. Reviewed 2026-10-28.

Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.