A dictionary stores data in key-value pairs. Use meaningful keys to make your code easy to understand.
A dictionary is a collection of data stored in key-value pairs. It is used to store information in an organized way.
student = {
"name":"Roshni",
"age":18,
"course":"BCA"
}
print(student)
Values can be accessed using their keys.
student = {
"name":"Roshni",
"age":18
}
print(student["name"])
student = {
"name":"Roshni"
}
student["age"] = 18
print(student)
student = {
"name":"Roshni",
"age":18
}
student.pop("age")
print(student)
student = {
"name":"Roshni",
"age":18
}
for key,value in student.items():
print(key,value)
mobile = {
"brand":"OnePlus",
"model":"Nord",
"year":2022
}
print(mobile["brand"])
A dictionary stores data using key-value pairs.
Yes, modern Python dictionaries maintain insertion order.
Yes, dictionaries are mutable and values can be updated.