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

#!/usr/bin/python3

dict1 = {'Name': 'Manni', 'Age': 7, 'Class': 'First'}
dict2 = dict1.copy()
print ("New Dictionary : ",dict2)

Result

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

New dictionary :  {'Name': 'Manni', 'Age': 7, 'Class': 'First'}
python_dictionary.htm
Advertisements