Google News
logo
Python - Interview Questions
What is a dictionary in Python?
The Python dictionary is a built-in data type. It defines a one-to-one relationship between keys and values. Dictionaries contain a pair of keys and their corresponding values. It stores elements in key and value pairs. The keys are unique whereas values can be duplicate. The key accesses the dictionary elements.
 
Keys index dictionaries.
 
Example :
 
The following example contains some keys Country Hero & Cartoon. Their corresponding values are India, Sivaji, and Chanti respectively.
 
>>> dict = {'Country': 'India', 'Hero': 'Sivaji', 'Cartoon': 'Chanti'}  
>>>print dict[Country]  
India  
>>>print dict[Hero]  
Sivaji 
>>>print dict[Cartoon]  
Chanti
Advertisement