Python dictionary copy() Method
Advertisements
Description
The method copy() returns a shallow copy of the dictionary.
Syntax
Following is the syntax for copy() method
dict.copy()
Parameters
NA
Return Value
This method returns a shallow copy of the dictionary.
Example
The following example shows the usage of copy() method.
#!/usr/bin/python
dict1 = {'Name': 'Zara', 'Age': 7};
dict2 = dict1.copy()
print "New Dictinary : %s" % str(dict2)
Let us compile and run the above program, this will produce the following result:
New Dictinary : {'Age': 7, 'Name': 'Zara'}