Home / Python / Reference / Dictionary methods

Python dictionary copy() method

Return a shallow copy of a dictionary.

Syntax

dict.copy()

Like list.copy: a new dictionary, but values that are lists are still shared.

Parameters

None.

Return value

a new dict

Example

Code

a = {"x": 1}
b = a.copy()
b["x"] = 99
print(a, b)

Output

{'x': 1} {'x': 99}

Related

Learn it step by step in the free lesson Dictionaries & Sets, with exercises that check your answers.