Python Tutorial for Beginners
Introduction to Python Dictionary
What are Dictionaries in Python?
Dictionaries in Python are unordered sets of data values that can be used to store data values like a map.
Unlike other data types, which can only carry a single value as an element, the dictionary can hold a key-value pair to make it more efficient.
Accessing Elements From a Dictionary
To access dictionary values in Python, look up the key name. Inside square brackets, the key can be used.
Example:
Dict = {1: 'WSC', 'name': 'For', 3: 'Python'}
# accessing an element using key
print("Accessing an element using key:")
print(Dict['name'])
# accessing an element using key
print("Accessing an element using key:")
print(Dict[1])
Output:
Accessing an element using key:
For
Accessing an element using key:
WSC