Dictionaries in Python are mutable, so items can be removed after creation.
pop( ) :
removes the key and returns the value
Python
student = { "name": "Rahul", "age": 22, "course": "CSE" } value = student.pop("age") print(student) print("Removed:", value) #output {'name': 'Rahul', 'course': 'CSE'} Removed: 22 del :
Deletes the key value pair permanently
Python
student = { "name": "Rahul", "age": 22, "course": "CSE" } del student["course"] print(student) #output {'name': 'Rahul' , 'age': 22} popitem( ) :
Removes and returns the last inserted key–value pair.
Python
student = { "name": "Rahul", "age": 22, "course": "CSE" } item = student.popitem() print(student) print("Removed:", item) #output {'name': 'Rahul', 'age': 22} Removed: ('course', 'CSE') clear( ) :
Removes all dictionary items but keeps the dictionary object.
Python
student = { "name": "Rahul", "age": 22, "course": "CSE" } student.clear() print(student) #output {}