Removing Dictionary Items
Dictionary items can be removed using built-in deletion methods that work on keys:
- del: removes an item using its key
- pop(): removes the item with the given key and returns its value
- clear(): removes all items from the dictionary
- popitem(): removes and returns the last inserted key–value pair
Output
Iterating Through a Dictionary
A dictionary can be traversed using a for loop to access its keys, values or both key-value pairs by using the built-in methods keys(), values() and items().
Output
No comments:
Post a Comment