Python Dictionary copy() MethodPython Functions


They copy() method gets a shallow copy of the dictionary.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

dict1 = {'Name': 'Gerryzhang', 'Age': 24,'Tel':123}
print(dict1)

dict2=dict1.copy()
print(dict2)

Output:

{'Name': 'Gerryzhang', 'Age': 24, 'Tel': 123}
{'Name': 'Gerryzhang', 'Age': 24, 'Tel': 123}

Syntax

dictionary.copy()

Parameters

The method doesn’t take any parameters.

Return Value

It returns a shallow copy of the dictionary.

© 2021 Programtips.org, all rights reserved. Privacy Policy | Contact Us