← Python

Dictionaries – Methods (keys, values, items, get)

Dictionary methods return views or values: .keys(), .values(), .items(), and .get()

What it does: .get(key, default) is safe — returns the default instead of raising a KeyError. .items() returns (key, value) tuples — great for iterating with unpacking. .keys() gives the left side of each pair — the lookup labels. The second argument to .get() is the fallback when the key is missing. pop() both removes the key and gives you its value in one step. update() merges another dict in — new keys are added, existing ones overwritten. len() counts the number of key-value pairs, not the total characters. in checks keys by default — use 'name' in d.values() to check values.

Common mistakes: It's keys() with an 's': not key(). It's values() with an 's': not value().

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does .keys() return?
All the keysAll the values
Matches
❌ d = {'a': 1} d.get('b') print(d['b'])
Error: .get() doesn't add the key
Applying
Meanings
Term
.keys()
Meaning
Returns all keys in the dictionary.
Practice
d = {'a': 1, 'b': 2}
Testing
Gaps
print(d.( ))
Check Answer
Spots
1d = {'a': 1, 'b': 2}
2all_keys = d.key()

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Hermit Crab' badge — Definition Collector, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does .keys() return?
A. All the keys ✓
B. All the values
.keys() gives the left side of each pair — the lookup labels
2. What does .values() return?
A. All the keys
B. All the values ✓
.values() gives the right side — the data stored under each key
3. What does .items() return?
A. Key-value pairs as tuples ✓
B. Just keys
.items() gives both together — each pair as a (key, value) tuple
4. d.get('x', 0) what happens if 'x' doesn't exist?
A. KeyError
B. Returns 0 (the default) ✓
The second argument to .get() is the fallback when the key is missing
5. d.get('x') what if 'x' doesn't exist and no default?
A. Returns None ✓
B. KeyError
.get() never raises KeyError — it returns None if no default is given

Match the Pairs

d = {'a': 1} d.get('b') print(d['b']) Error: .get() doesn't add the key
d = {'x': 5} d.pop('y') Error: Key 'y' not in dict
d.get('missing', 0) Valid: Returns 0 if key absent
for k, v in d.items(): print(k, v) Ok: Loop over key-value pairs
d = {'a':1,'b':2} print(list(d.keys())) Output: ['a', 'b']
d = {'a':1} print(d.get('b', 99)) Output: 99

Key Term

.keys()
Returns all keys in the dictionary.~~.values()

Fill in the Blanks

1. d = {'a': 1, 'b': 2} print(d.keys( ))
2. d = {'a': 1, 'b': 2} print(d.values( ))
3. d = {'a': 1} print(d.get('b', 0))
4. d = {'x': 10} val = d.pop('x')
5. d = {'a': 1} d.update({'b': 2})

Spot the Error

Question 1
A d = {'a': 1, 'b': 2}
B all_keys = d.key()
C print('Keys:', all_keys)
D print('Done')
Line B — It's keys() with an 's': not key()
Question 2
A d = {'a': 1, 'b': 2}
B all_vals = d.value()
C print('Values:', all_vals)
D print('Done')
Line B — It's values() with an 's': not value()
Question 3
A d = {'a': 1, 'b': 2}
B all_items = d.item()
C print('Items:', all_items)
D print('Done')
Line B — It's items() with an 's': not item()
Question 4
A d = {'a': 1, 'b': 2}
B val = d.get['b']
C print('Value:', val)
D print('Done')
Line B — Use parentheses () to call methods, not square brackets []
Question 5
A result = {'a': 1, 'b': 2}.pop()
B label = 'Dict'
C print('Result:', result)
D print('Done')
Line A — dict.pop() requires a key argument: which key to remove?
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?