Click for All Topics
.clear()
method doesn’t take any argument and doesn’t return anything.Syntax –
dictionary.clear()
Parameters –
Example –
my_dict={'1':'a','2':'b','3':'c','4':'d'}
print("Original Dictionary:",my_dict)
my_dict.clear()
print("Original Dictionary after clear:",my_dict)
# Output -
# Original Dictionary: {'1': 'a', '2': 'b', '3': 'c', '4': 'd'}
# Original Dictionary after clear: {}
.clear()
method.
Example – Clear an empty dictionary
dct={}
print("Original Dictionary:",dct)
dct.clear()
print("Original Dictionary after clear:",dct)
# Output -
# Original Dictionary: {}
# Original Dictionary after clear: {}
Example –
my_dict={'name':'xyz', 'roll no':1,'year':4}
print("Original Dictionary:",my_dict)
return_value=my_dict.clear()
print("Original Dictionary after clear:",my_dict)
print("Return Value of clear method:",return_value)
# Output -
# Original Dictionary: {'name': 'xyz', 'roll no': 1, 'year': 4}
# Original Dictionary after clear: {}
# Return Value of clear method: None
Office:- 660, Sector 14A, Vasundhara, Ghaziabad, Uttar Pradesh - 201012, India