= {'Sarah':'476-3321', 'Nathan':'351-7743'}
phones = {'Name':'Molly', 'Age':18}
users = {} # an empty dictionary emp
Dictionaries
- 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:
'Bob'] = '123-4567'
phones[print(phones)
{'Sarah': '476-3321', 'Nathan': '351-7743', 'Bob': '123-4567'}
Or also change values using the keys:
'Sarah'] = '999-9999'
phones[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'}