student = {"name": "John", "age": 20, "grade": "A"}
print(student["age"])
#source code --> clcoding.com
Code Explanation:
Creating the Dictionary
student = {"name": "John", "age": 20, "grade": "A"}
A dictionary named student is created using {} (curly brackets).
The dictionary consists of key-value pairs:
"name" → "John" (String)
"age" → 20 (Integer)
"grade" → "A" (String)
Accessing the "age" Value
print(student["age"])
The print() function is used to display output on the screen.
student["age"] retrieves the value associated with the key "age" from the dictionary.
In this case, student["age"] returns 20.
0 Comments:
Post a Comment