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

#!/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
Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements