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.

Live Demo
#!/usr/bin/python

dict1 = {'Name': 'Zara', 'Age': 7};
dict2 = dict1.copy()
print "New Dictionary : %s" %  str(dict2)

When we run above program, it produces following result −

New Dictionary : {'Age': 7, 'Name': 'Zara'}

python_dictionary.htm

Advertisements