Creation and use of dictionaries

A Dictionary  is a way to store data just like a list, but instead of using only numbers to get the data, you can use almost anything. This lets you treat a dictionary like it’s a database for storing and organizing data any kind of data:

>>> stuff = {'name': 'Zed', 'age': 39, 'height': 6 * 12 + 2}
>>> print stuff['name']
Zed
>>> print stuff['age']
39
>>> print stuff['height']
74
>>> stuff['city'] = "San Francisco"
>>> print stuff['city']
San Francisco

And that’s it. It is just really another kind of list, and a little bit simple once you get the hang of it

Examples and more at: https://learnpythonthehardway.org/book/ex39.html

 

Deja un comentario