Explain the dictionary in Python.
Answer / chaitanya
Python's built-in data type is dictionary, which defines one-to-one relationships between keys and values.
Dictionaries consist of pairs of keys and their corresponding values.
Dictionaries are indexed by keys.
Dictionary is similar to associative array or hash table of other languages.
As following example explains further- India, Angel & Cartoon are keys & their corresponding values are Bharat, Mother Teresa & Mickey respectively.
>>> dict = {'India': 'Bharat', 'Angel': ‘Mother Teresa’, 'Cartoon': 'Mickey'}
>>>print dict[India]
Bharat
>>>print dict[Angel]
Mother Teresa
| Is This Answer Correct ? | 2 Yes | 0 No |
What are the key features of Python?
What is a negative index in python?
How do you split a list into evenly sized chunks in python?
What is python with statement?
Narrate the difference between python arrays and lists.
What are Python's key features?
When do you choose a list over a tuple?
What is the output of this code?
How to print without newline or space?
Why Lambda is used in Python?
How to find whether string is alphanumeric or not?
Why isn't there a switch or case statement in python?