logo

Python Dictionary Copy() Method


Show

Description

Python dictionary method copy() revisits a low copy of the dictionary. The copy() technique arrivals a thin copy of the list. The difficulty with copying the catalog in this method is that if you adopt the new_list, the old_list is also customized. Yet, if you require the innovative list unchanged when the original list is modified, you can utilize the copy() method. This is called superficial copy.

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 the copy() method.

#!/usr/bin/python

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

When we run the above program, it produces the following result:

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

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.