Menu Close

Python Dictionary copy Method

Here in this dictionary method guide, we are going to learn all about the Python dictionary copy method to create a copy of the dictionary.


Dictionary copy method in python returns a new copy of the existing python dictionary.
In the previous tutorial, we have learned the python dictionary clear() method to remove all the items from the dictionary.

To understand this example, you would have basic knowledge of Python Dictionary.

Table of Contents

Python Dictionary copy Method

copy function in Python is a dictionary built-in function, that is used to create and return a copy of the dictionary.

Syntax

The syntax of python dictionary copy method is:-

dictionary.copy()

Parameter

Dictionary copy function in Python does not take any parameter.

Return Value

Return value of dictionary copy method in python is new copied dictionary.

Python dictionary clear example

Create copy of the existing dictionary using copy() dictionary method.

Example:

myDict= { 	

	"id":12,
	"first_name":"Maria",
	"last_name":"Alex",
	"city":"New Yark",
	"salary":"$1000"
		
}
result = myDict.copy()
print(result)

Output

{'id': 12, 'first_name': 'Maria', 'last_name': 'Alex', 'city': 'New Yark', 'salary': '$1000'}

Conclusion

In this guide, you have seen all about the dictionary copy method to create a copy of the existing python dictionary.
If this article helped you, please continue visiting for further interesting python tutorial.

For More Information:- Click Here

Previous Article
Next Article

Related Posts

Leave a Reply