Python Removing key-value pairs
Removing key-value pairs
You can remove any key-value pair you want from a dictionary. To do so use the del keywords and dictionary name, followed by the key in square brackets. This will delete the key and its associated value.
You can remove any key-value pair you want from a dictionary. To do so use the del keywords and dictionary name, followed by the key in square brackets. This will delete the key and its associated value.
#Deleting a key-value pair
alien_0 = {'color': 'green', 'points': 5}
print(alien_0)
del alien_0['points']
print(alien_0)

No comments:
Post a Comment