How do we define dictionary in Python?


Dictionary object is an unordered collection of key-value pairs, separated by comma and enclosed in curly brackets. Association of value with key is marked by : symbol between them.

>>> D1={'a':1,'b':2,'c':3}

Key can appear in a dictionary object only once, whereas single value can be assigned to multiple keys. Key should be of immutable data type i.e. number, string or tuple.

>>> D2={1:'aaa', 2:'bbb', 3:'ccc'}
>>> D3={(10,10):'x1', (20,20):'x2'}
>>> D4={'Microsoft':['MS Office', 'Windows', 'C#'], 'Oracle':['Oracle', 'Java', 'MySQL']}


Updated on: 25-Feb-2020

117 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements