Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
