Menu Close

Python Dictionary clear Method

In this tutorial, we are going to learn all about the Python dictionary clear method to clear the items of the dictionary.
Sometimes we want to remove all the items from the string to store another data, then we have the best method that is a clear method.

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

Python Dictionary clear Method

clear function in Python is a dictionary built-in function, that is used to clear all the items from the dictionary.

Syntax

The syntax of clear function in Python is:-

dictionary.clear()

Parameter

Dictionary clear function in Python does not take any parameter.

Python dictionary clear example

Here we use clear function remove all the items from the dictionary.

Example:

myDict= { 	

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

Output

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

Conclusion

In this tutorial, you have learned the Python dictionary clear method to remove all the items from the dictionary.
If this article helped you, please share with others and keep continue for further interesting python articles.

For More Information:- Click Here

Next Article

Was this post helpful?

Related Posts

Leave a Reply