Python Dictionary clear Function

Python clear Dictionary function is used to clear or remove total items (key value pairs) from a Dictionary. In this section, we discuss how to use this Python Dictionary clear function with practical examples.

The basic syntax behind this clear function is:

dictionary_name.clear()

Python Dictionary clear Example

The Python clear function removes keys, values in a given dictionary. The code below removes items from the emp dictionary.

TIP: Please refer to the Dictionary article to understand everything about Python Dictionaries.

# Python Dictionary clear Example

emp = {'name': 'John', 'age': 25 , 'job': 'HR', 'Sal': 725000}

print("Dictionary: ", emp)
print("Dictionary Length: ", len(emp))

emp.clear()
print("\nDictionary: ", emp)
print("Dictionary Length: ", len(emp))
Python Dictionary clear 1