Python Removing key-value pairs - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Python Removing key-value pairs - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Thursday, December 6, 2018

Python Removing key-value pairs

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.

#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

Post Top Ad