Python Dictionary copy function

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



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)
Dictionary copy Example 1