Saturday, February 25, 2023

Python dictionaries

Here we will be discussing an important python data type dict. Python dict is an unordered collection of items. Each dictionary item holds a key:value pair, python dictionaries are optimized to retrieve values when key is known.
In python, an empty dictionary is defined using empty curly braces {}.

Inserting an Element to Python Dictionary:
Length of dictionary is 0 zero, dictionary do not contain any element and its empty. We will see how we can add elements to an empty dictionary.

Elements can also be added during the initialization of dictionary itself. Let us see an example 

Dictionary created above has strings in both keys and values. It can also contain mixed data types. Python Dictionary is a heterogenous.

In the next chapter operations on Python Dictionaries we will discuss different operations on dictionary like accessing elements, updating elements, removing elements, Listing all the keys  

No comments:

Post a Comment

Operations on Python Dictionaries