Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Dictionary

  • dictionary

  • dict

  • {}

  • We can start from an empty dictionary and then fill it witg key-value pairs.

user = {}
user['name'] = 'Foobar'
print(user)        # {'name': 'Foobar'}

user['email'] = 'foo@bar.com'
print(user)        # {'name': 'Foobar', 'email': 'foo@bar.com'}

the_name = user['name']
print(the_name)    # Foobar

field = 'name'
the_value = user[field]
print(the_value)   # Foobar

user['name'] = 'Edith Piaf'
print(user)      # {'name': 'Edith Piaf', 'email': 'foo@bar.com'}