The clear() function is used to remove all elements from the dictionary.
Example
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
dict = {'Name': 'Gerryzhang', 'Age': 24}
print ("the length of dictionary is: %d" %len(dict))
dict.clear()
print ("the length of dictionary is: %d" %len(dict))
Output:
the length of dictionary is: 2
the length of dictionary is: 0
Syntax
dictionary.clear()
Parameters
The method doesn’t take any parameters.
Return Value
It returns none.