Python 3.7.1 Dictionaries
Dictionaries are kind of like lists and tuples but, instead of using index numbers, they use keys to point to values.
numbers = {"one": "un", “two”: “deux”}print(numbers)CONSOLE OUTPUT
{'one': 'un', 'two': 'deux'}In order to create a dictionary, we enclose pairs of keys and values in braces and assign them to a variable.
Unlike the index numbers of lists and tuples, keys can be any type.
numbers = {"one": "un", "two": "deux"}numbers “three” = “trois”numbers[True] = “quatre”print(numbers)CONSOLE OUTPUT
{‘one’: ‘un’, ‘two’: ‘deux’, 3: ‘trois’, True: ‘quatre’}Even boolean values are used as keys.
But how can we get to the values in a dictionary?
n = {"one": "un", "two": "deux"}print (n[“one”])CONSOLE OUTPUT
unKind of how we add values to dictionaries, we put a key in a pair of brackets to access the value that it points to.