Explain the dictionary in Python.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Are tuples mutable?

422


What is private method in python?

443


What are migrations in python?

433


Is python based on c?

471


How would you generate a random number in python?

460






Do you know how memory is managed in python?

454


What does quit () do in python?

433


What do you mean by instance?

430


What does none mean in python?

425


Can python make websites?

419


What does != Mean in python 3?

453


What good is recursion?

509


What super does in python?

436


What is micropython?

473


How do you exit a python script?

459