Explain the dictionary in Python.



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

Post New Answer

More Python Interview Questions

What is python used for today?

1 Answers  


How can you identify the data type of any variable in python?

0 Answers  


How would you create an empty numpy array in python?

0 Answers  


Python read a single character from the user?

0 Answers  


What is python? What are the benefits of using python? What do you understand of pep 8?

0 Answers  


Difference between __str__ and __repr__ in python?

0 Answers  


Can you explain this why are we getting an error here?

0 Answers  


How do you add elements to a list in python?

0 Answers  


What are methods in python?

0 Answers  


Do you always need a default constructor?

0 Answers  


What's a python script?

0 Answers  


What are loops in python?

0 Answers  


Categories