- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the basic syntax to access Python Dictionary Elements?
You can access a dictionary value to a variable in Python using the access operator [].
example
my_dict = { 'foo': 42,'bar': 12.5 } new_var = my_dict['foo'] print(new_var)
Output
This will give the output −
42
You can also access the value using the get method on the dictionary.
example
my_dict = { 'foo': 42,'bar': 12.5 } new_var = my_dict.get('foo') print(new_var)
Output
This will give the output −
42
- Related Articles
- What is correct syntax to create Python dictionary?
- What is basic syntax of Python for Loops?
- What is basic syntax of Python if...else statement?
- How to optimize Python dictionary access code?
- How to access Python dictionary in simple way?
- What is correct syntax to create Python tuples?
- What is correct syntax to create Python lists?
- Delete Dictionary Elements in Python
- What is python .. ("dot dot") notation syntax?
- How to access nested Python dictionary items via a list of keys?
- What is the syntax of Python if...elif...else statement?
- What is syntax of tuple declaration in Python?
- What is correct syntax of Python if statement?
- What are the basic elements of computers related to OS?
- How to remove all the elements of a dictionary in Python?

Advertisements