Python Dictionary

A Dictionary in python is key-value pairs separated by comma. Dictionary is defined using curly braces { }.

Important thing to remember is, the keys must be immutable and values can be any valid python object.

Hence, keys could be a number, string, tuple etc. and values could be number, string, tuple, lists, dictionaries etc.

Sample Output:

Creating a dictionary in python
Creating a dictionary in python

A Dictionary can contain a dictionary inside it

Python dictionaries are one of the most complex data structures. It can contain any valid python object as values. Hence, it can contain a dictionary only as values, not as a key because, the keys of a dictionary must be immutable data types.

Sample Output:

A python dictionary can contain a dictionary inside it
A python dictionary can contain a dictionary inside it

Common Dictionary commands

Whenever you create a new object in python, there are a set of pre-built methods which gets assigned to it and are available to use. You can check these list of functions using a dot(.) + tab button.

Available functions for dictionaries
Available functions for dictionaries

Sample Output:

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!

Leave a Reply!

Your email address will not be published. Required fields are marked *