- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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']}
- Related Articles
- How do we define tuple in Python?
- How do we define lists in Python?
- How to define a Python dictionary within dictionary?
- How do we define drift speed?
- How do Python Dictionary Searching works?
- How do we define a dialog box in HTML?
- How do Python dictionary hash lookups work?
- How can we read Python dictionary using C++?
- How we can translate Python dictionary into C++?
- How do we define an area in an image map with HTML?
- How do we use function literal to define a function in JavaScript?
- How do we declare variable in Python?
- How do we provide comments in Python?
- How can we return a dictionary from a Python function?
- How do we use enum keyword to define a variable type in C#?

Advertisements