Open In App

Few mistakes when using Python dictionary

Usually, A dictionary is a collection which is unordered, changeable and indexed. In Python, dictionaries are written with curly brackets, and they have keys and values. Each key-value pair in a Dictionary is separated by a ‘colon’, whereas each key is separated by a ‘comma’.




my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
print(my_dict)

Output:
{1: 'Geeks', 2: 'For', 3: 'Geeks'}

We generally use dictionaries to access the items with its key value, inside square brackets.




my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
print(my_dict[1])
print(my_dict[2])
print(my_dict[3])

Output:

Geeks
For
Geeks

The common operations of dictionaries are:

Common mistakes while using dicts and overcomes

When not to use dicts


Article Tags :