Menu Close

Python Dictionary copy Method

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.


The 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.

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 the python dictionary copy method is:-

dictionary.copy()

Parameter

The Dictionary copy function in Python does not take any parameter.

Return Value

The return value of the dictionary copy method in python is a new copied dictionary.

Python dictionary clear example

Create a copy of the existing dictionary using the 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 tutorials.

For More Information:- Click Here

Python Dictionary pop() Method
Python Dictionary values Method

Related Posts