The clear() function in python is used to delete all the elements from the dictionary.After this method calling the dictionary gets initialized to an empty dictionary.
dict.clear()
clear() method doesn't take any parameters.If we call clear function on a dictionary reference, the actual dictionary content is removed, and hence all references referring to the actual dictionary also become empty.
clear() method doesn't return any value (returns None).
dict = {5: "five", 6: "six"}
dict.clear()
print('dic =', dict)
Output:
dic = {}
my_namelist = [12, 'Siya', 'Tiya', 14, 'Riya', 12, 'Riya']
#Using clear() method
element = my_namelist.clear()
print(element)
print(my_namelist)
Output:
None []