Home >>Python Dictionary Methods >Python Dictionary clear() Method
Python Dictionary clear() Method removes all the items from a list. It returns nothing by clear the list completely. It does not require parameter.
Syntax:dictionary.clear()Here is an example of Python Dictionary clear() Method:
color = {
"color1": "red",
"color2": "blue",
"color3": "green"
}
color.clear()
print(color)
t1 = {1: "php", 2: "tpoint"}
t2 = t1
t1.clear()
print('After removing items using clear()')
print('t1 =', t1)
print('t2 =', t2)
t1 = {1: "red", 2: "blue"}
t2 = t1
t1 = {}
print('After removing items by assigning {}')
print('t1 =', t1)
print('t2 =', t2)