Python dictionary copy() Method


Contents

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 adapt 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 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 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'}

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



Navigation
Tutorial
Tutorial
Tutorial