student = {"name": "John", "age": 20, "grade": "A"}
print("Age:", student["age"])
#source code --> clcoding.com
Code Explanation:
Define the Dictionary:
student = {"name": "John", "age": 20, "grade": "A"}
A dictionary named student is created.
It consists of key-value pairs:
"name" → "John"
"age" → 20
"grade" → "A"
Access the Value of "age":
student["age"]
The key "age" is used inside square brackets [ ] to retrieve its corresponding value, which is 20.
Print the Retrieved Value:
print("Age:", student["age"])
The print() function outputs:
Age: 20
0 Comments:
Post a Comment