Python Dict Methods

Beginner
5 min read
Updated: Nov 2026
11 method guides
Method index

About This Index

This page is the Python Dict Methods index for the tutorial track. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example prints fixed data, and since dicts keep insertion order, the output you see is the output you get.

Learn what keys can be, how ordering works, and the classic mistakes on the Dict hub. Use this page when you need a specific method such as get(), setdefault(), or items().

Eleven methods, one type.

Every method below belongs to the built-in dict type, so no import is needed. All are called on a dict object except fromkeys(), a classmethod called as dict.fromkeys(...). The Returns column tells you whether you get a value, a live view, a new dict, or None.

How to Call a Dict Method

Write the dict, a dot, the method name, and the arguments. Some methods return a value or a live view; update() and clear() only change the dict and return None:

Python
stock = {"apples": 5, "pears": 2}
print(stock.get("plums", 0))        # 0
stock.update(plums=7)               # add or overwrite keys
print(stock.pop("pears"))           # 2
print(list(stock.keys()))           # ['apples', 'plums']
print(stock.setdefault("figs", 1))  # 1
print(stock)                        # {'apples': 5, 'plums': 7, 'figs': 1}

Python Dict Methods Table

All method guides in this Python tutorial series (11 tutorials), grouped by purpose.

Read keys, values, and items

4 methods

Look up one value safely, or get a live view of every key, every value, or every key/value pair for loops and membership tests.

MethodReturnsDescriptionTutorial
get()value or defaultReturn the value for a key, or a default instead of raising KeyError.Try it
keys()dict_keys viewReturn a live, set-like view of the keys of a dict.Try it
values()dict_values viewReturn a live view of the values of a dict, for sums, counts, and checks.Try it
items()dict_items viewReturn a live view of (key, value) pairs for loops, sorting, and comparisons.Try it

Add and update entries

3 methods

Merge other data into a dict, insert a default only when a key is missing, or build a new dict from a list of keys.

MethodReturnsDescriptionTutorial
update()NoneMerge keys from another dict, a list of pairs, or keyword arguments, in place.Try it
setdefault()value for keyReturn the value of a key, inserting a default first if the key is missing.Try it
fromkeys()new dictBuild a new dict from a list of keys, all set to the same value.Try it

Remove entries

3 methods

Take out one key and get its value back, take out the most recently inserted pair, or empty the whole dict in place.

MethodReturnsDescriptionTutorial
pop()removed valueRemove a key and return its value, with an optional default for missing keys.Try it
popitem()(key, value) tupleRemove and return the last inserted (key, value) pair.Try it
clear()NoneRemove every key/value pair in place, leaving an empty dict.Try it

Copy a dict

1 method

Make a new, independent top-level dict that still shares nested lists and dicts with the original.

MethodReturnsDescriptionTutorial
copy()new dict (shallow)Return a shallow copy: a new dict that still shares nested lists and dicts.Try it

Dict Operators and Idioms

These are not named methods, but you will use them next to the methods above in almost every program:

CodeWhat it does
d[key]Read the value for key; raises KeyError if the key is missing.
d[key] = valueAdd the key, or overwrite its value; an existing key keeps its position.
del d[key]Remove the key; raises KeyError if it is missing.
key in dTrue if the key exists (checks keys only, never values).
len(d)Number of key/value pairs.
for key in d:Loop over the keys in insertion order.
d | otherNew merged dict; values from other win (Python 3.9+).
d |= otherMerge other into d in place, like update() (Python 3.9+).
Python
ages = {"Tom": 31}
ages["Uma"] = 27             # add a key
print(ages["Tom"])           # 31
print("Uma" in ages)         # True
del ages["Tom"]              # remove a key
print(len(ages))             # 1
merged = ages | {"Vic": 40}  # new dict (3.9+)
ages |= {"Uma": 28}          # update in place (3.9+)
print(merged, ages)          # {'Uma': 27, 'Vic': 40} {'Uma': 28}

Use get() instead of d[key] when a missing key is normal, and pop() instead of del when you also need the removed value. On Python 3.8, write {**ages, "Vic": 40} instead of |.

Frequently Asked Questions

They are the functions you call on a dictionary with dot notation, such as prices.get("tea") or prices.update(other). They read, add, update, remove, or copy key/value pairs.
This index covers all 11 public dict methods: clear(), copy(), fromkeys(), get(), items(), keys(), pop(), popitem(), setdefault(), update(), and values().
clear(), pop(), popitem(), setdefault() (when the key is missing), and update() change the dict in place. get(), keys(), values(), items(), and copy() leave it unchanged, and fromkeys() builds a new dict.
They are operators and statements, not named methods, but they work on every dict and appear in the operators table on this page. The | and |= merge operators need Python 3.9 or newer.
Read the Python Dict hub first for keys, ordering, and common mistakes. Then open get(), items(), update(), setdefault(), and pop() from the tables below.

Start with clear()

Open the first guide in the list and work your way through the dict methods.

clear() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful