Python Dictionaries
Introduction Dictionaries are used to store values in key: value pairs,
- A simple dictionary, simple_dict = { "age": 29, "country": "Ke", "gender": "Female" } Print the dictionary: print(simple_dict) # outputs {'age': 29, 'country': 'Ke', 'gender': 'Female'} 2. Access the dictionary items Print “age” value: print(simple_dict["age"]) # outputs: 29 Duplicate keys are not allowed. simple_dict = { "age": 29, "age": 30, "country": "Ke", "gender": "Female" } print(simple_dict) # outputs: {'age': 30, 'country': 'Ke', 'gender': 'Female'} 3.
2 minutes to read