Dictionaries and Related Operations

A dictionary stores data as key-value pairs, letting you look up a value quickly using a meaningful key instead of a numeric index.

Creating a Dictionary

student = {
    "name": "Rahul",
    "age": 22,
    "course": "Data Science"
}

Accessing and Updating Values

print(student["name"])
student["age"] = 23
student["city"] = "Noida"

Common Dictionary Methods

print(student.keys())
print(student.values())
print(student.items())
print(student.get("email", "Not Provided"))

Looping Through a Dictionary

for key, value in student.items():
    print(key, ":", value)
Dictionaries closely resemble JSON data, which is one of the most common formats used to exchange data between APIs, files, and web applications.

Coming Up

With Python's core data structures covered, the next topic shifts to writing your own reusable blocks of code with user defined functions.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course