xxxxxxxxxx
# Basic syntax:
copied_dict = dict(original_dict) # or:
copied_dict = original_dict.copy()
xxxxxxxxxx
original = {1:'one', 2:'two'}
new = original.copy()
# removing all elements from the list
new.clear()
print('new: ', new)
print('original: ', original)
xxxxxxxxxx
# This method returns a shallow copy of the dictionary.
# It doesn't modify the original dictionary.
original_marks = {'Physics':67, 'Maths':87}
copied_marks = original_marks.copy()
xxxxxxxxxx
1
2
new_person = person.copy()
new_person = dict(person) # another way to create a copy of dictionary
Copied!