The  Dictionary is one of the popular data structures in Python. We often come across the times when we need to copy the elements of the dictionary from one to another. This is where the dictionary copy() method.

Python Dictionary copy()

Python dictionary copy() is an inbuilt function that returns a copy of a specified dictionary. The copy() function returns a shallow copy of the dictionary. The copy() method doesn’t take any parameters. It doesn’t modify the original dictionary.

The syntax of the copy() method in the Python Dictionary is the following.

dictionary.copy()

See the following example.

## app.py

appDict = { 
    'shopping': 'flipkart',
    'transport': 'ola',
    'banking': 'paytm',
    'hotel': 'oyo rooms'
 }
secDict = appDict.copy()
print(secDict)

See the below output.

Python Dictionary Copy Example | copy() Method Tutorial

In the above example, an exact copy of appDict is created and assigned to the secDict.

#python #python dict copy

Python Dictionary Copy Example | Python dict copy()
1.30 GEEK