Create Dictionary
Lesson 3 of 14 in Coddy's Dictionary in Python course.
To create a dictionary use the following syntax,
my_dict = {
"name": "Alice",
"age": 30, "city":
"New York"
}In this example, "name", "age", and "city<strong>"</strong> are keys, and "Alice", 30, and "New York" are their respective values.
Challenge
Easycreate a variable named person and assign to it a dictionary with following key values:
- The value
"John Doe"with the key"name" - The value
25with the key"age" - The value
"Los Angeles"with the key"city" - The value
"johndoe@example.com"with the key"email"
Try it yourself
# Write code hereAll lessons in Dictionary in Python
2Operations
Create DictionaryAccessing ItemsChange ValuesAdding ItemsRemoving ItemsCheck if a key existsLoop Through a Dictionary