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

What are special methods in python and how to implement?

611


Get the cartesian product of a series of lists?

566


How do I install pip on windows?

663


How to get a list of class attributes in python?

603


What is the use of negative indices?

624






How to compare two list?

647


Rules for local and global variables in python?

669


What does none type mean in python?

561


How will you find, in a string, the first word that rhymes with ‘cake’?

1199


Are Tuples immutable?

601


Why we are using a python dictionary?

621


What is with open in python?

657


Explain tkinter in python

598


What is python keyword?

611


Can a class be static?

557