Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
130 views
in Python by (114k points)
How do you access values in a dictionary?

Please log in or register to answer this question.

1 Answer

0 votes
by (114k points)

You can access values in a dictionary by using the key as an index. In Python, dictionaries use a key-value mapping, where each key maps to a value. To access the value associated with a key in a dictionary, you simply use the key as an index to the dictionary. 

Here is an example:

person = {"name": "John", "age": 30, "city": "New York"}
print(person["name"]) # Output: John
print(person["age"]) # Output: 30
 

In this example, we create a dictionary person with three key-value pairs. To access the value associated with the key "name", we use the key as an index to the dictionary: person["name"]. This returns the value "John". Similarly, to access the value associated with the key "age", we use the key as an index to the dictionary: person["age"]. This returns the value 30.

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...