Home >>Python Dictionary Methods >Python Dictionary copy() Method

Python Dictionary copy() Method

Python Dictionary copy() Method

Python Dictionary copy() Method in python dictionary returns a shallow copy of the specified dictionary.

Syntax:
dictionary.copy()
Here is an Example of Python Dictionary copy() Method:

color = 
{
"color1": "orange",
"color2": "green",
"color3": "blue"
}
z = color.copy()
print(z)

Output:
{'color1': 'orange', 'color2': 'green', 'color3': 'blue'}
Example 2:

org = {1:'php', 2:'tpoint'} 
dup = org.copy() 
dup.clear() 
print('dup: ', dup) 
print('org: ', org)

Output:
dup: {}
org: {1: 'php', 2: 'tpoint'}

No Sidebar ads