Python Dictionary copy function

Python copy Dictionary function shallow copy the dictionary items (key value pairs). In this section, we discuss how to use this Dictionary copy function with practical examples.

The syntax of the Python Dictionary copy function is:


Python Dictionary copy Example

The copy dictionary function copies the keys, values in a given dictionary to another dictionary. The below code copy items in the emp dictionary to newEmp and newEmp2.

TIP: Please refer to the Dictionary to understand Python Dictionaries.

# Python Dictionary copy Example

emp = {'name': 'John', 'age': 25 , 'job': 'HR', 'Sal': 725000}

print("Dictionary: ", emp)
print("Dictionary Length: ", len(emp))

newEmp = emp.copy()
print("\nDictionary: ", newEmp)
print("Dictionary Length: ", len(newEmp))

newEmp2 = emp.copy()
print("\nDictionary: ", newEmp2)
Python Dictionary copy 1