Dictionary
1. What is Dictionary?
Ans: In Python, Dictionary is a comma separated key-value pairs within curly
braces. It is unordered, [Link] key in a dictionary is unique and is used to
access the associated value.
2. How to create Dictionary in Python?
Ans:
To create dictionary in Python use key-value pairs in curly braces.
Syntax:
Dict = {key1:val1, key2:val2, key3:val3}
For Example:
my_dict={'name':"Pooja",'age':24,'mobile_no.":9988776655,'city':"Pune"}
It will create dict in python
[Link] a Dict for 3 different cars
ans:
car_brands={
"Toyota":{"Model":"Camry","Year":2022,"Color":"Blue","Price":25000},
"Honda":{"Model":"Civic","Year":2021,"Color":"Red","Price":22000},
"Ford":{"Model":"Mustang","Year":2020,"Color":"Black","Price":30000}
}
print(car_brands)
#Output
#{'Toyota': {'Model': 'Camry', 'Year': 2022, 'Color': 'Blue', 'Price': 25000},
# 'Honda': {'Model': 'Civic', 'Year': 2021, 'Color': 'Red', 'Price': 22000},
# 'Ford': {'Model': 'Mustang', 'Year': 2020, 'Color': 'Black', 'Price': 30000}}