Python Dictionary copy function

This Python function shallow copy the dictionary items (key value pairs) and the syntax of it is:

dictionary_name.copy()

Python Dictionary copy Example

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

TIP: Please refer to the Dictionary to understand them in Python.

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