Day 27 Of Documenting My Learning Journey
Published: (December 19, 2025 at 02:42 PM EST)
1 min read
Source: Dev.to
Source: Dev.to
What I learnt Today
- How to define dictionaries using the
dictconstructor and curly braces{}. - How to access elements in a dictionary using the
.get()method and bracket notation[]. - How to add and update elements in a dictionary.
- How to loop through keys, values, and both keys and values using a
forloop.
On what I learnt Today
Assumption: we have a dictionary named person.
Defining
person = {
"name": "James",
"age": 23,
"Occupation": "Engineer"
}
Accessing Elements
print(person["name"]) # or
print(person.get("name"))
Adding Elements
person["status"] = "Graduated"
Updating Elements
person["age"] = 20
Removing an Element
person.pop("status")
Looping through Keys
for key in person:
print(key)
Looping through Values
for value in person.values():
print(value)
Looping through Keys and Values
for key, value in person.items():
print(f"{key} -> {value}")
Resources I used
- Python refresher series by Bonaventure Ogeto on YouTube.
What’s Next
- Understanding sets and tuples.