Dictionary copy() method Python

The Python dictionary copy() method copies the item from one dictionary to another.This method does not accept any argument.

>>> d1={ 23:45 , 'Pink':'User' , 'Howling':'Wolf'}
>>> d2=d1.copy()
>>> d2
{23: 45, 'Pink': 'User', 'Howling': 'Wolf'}

Instead of using this method you can also direct assignment to copy the items.

>>> d1={ 23:45 , 'Pink':'User' , 'Howling':'Wolf'}
>>> d3=d1
>>> d3
{23: 45, 'Pink': 'User', 'Howling': 'Wolf'}


Leave a Reply

Your email address will not be published. Required fields are marked *