Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dictionary basics
6. Adding and editing dictionary elements
Dictionaries in loops and conditional statements
Dictionaries in functions
Summary

Instruction

Perfect! You can also use square brackets to add or edit a dictionary element:

phonebook = {'Mary': '8349374', 'Anne': '7439834', 'John': '3472983'}
phonebook['Mary'] = '8740334'

In the code above, if the dictionary contains a key 'Mary', the associated value will be updated. If the dictionary does not contain the given key, the key-value pair will be added to the existing dictionary:

phonebook['Jack'] = '6667384'

This code will add a new key 'Jack' to the dictionary and map it to the given string value. Jack's phone number is 6667384.

Exercise

Add a new element to the dictionary: Windows XP, released in 2001.

Stuck? Here's a hint!

Use: os_releases[2001]