Dictionary copy() Method



Description

Python dictionary 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.

dict = {'Name': 'Zara', 'Age': 7};
print "Start Len : %d" % len(dict)
dict.clear()
print "End Len : %d" % len(dict)

When we run above program, it produces following result −

New Dictionary : {'Age': 7, 'Name': 'Zara'}
python_dictionary_methods.htm
Advertisements