How do we define dictionary in Python?

PythonServer Side ProgrammingProgramming

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']}


raja
Published on 08-Feb-2018 23:36:53
Advertisements