phones = {'Sarah':'476-3321', 'Nathan':'351-7743'}
users = {'Name':'Molly', 'Age':18}
emp = {} # an empty dictionaryDictionaries
- Mapping types: have keys which map to values
- A pair of key and value is called an entry
- Dictionaries are NOT ORDERED! But they are subscriptable (with the keys - which have to be immutable objects)
You can add a new entry by just specifying it:
phones['Bob'] = '123-4567'
print(phones){'Sarah': '476-3321', 'Nathan': '351-7743', 'Bob': '123-4567'}
Or also change values using the keys:
phones['Sarah'] = '999-9999'
print(phones){'Sarah': '999-9999', 'Nathan': '351-7743', 'Bob': '123-4567'}
To delete, use:
del phones['Nathan']
print(phones){'Sarah': '999-9999', 'Bob': '123-4567'}