Last Updated : 11 Jul, 2025
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’.
Python3 1==
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.
Python3 1==
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
print(my_dict[1])
print(my_dict[2])
print(my_dict[3])
The common operations of dictionaries are:
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
print(my_dict.values())
Output:
dict_values(['Geeks', 'For', 'Geeks'])
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
print(my_dict.keys())
Output:
dict_keys([1, 2, 3])
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
my_dict[4]='Python'
print(my_dict)
Output:
{1: 'Geeks', 2: 'For', 3: 'Geeks', 4: 'Python'}
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
my_dict[3]='Python'
print(my_dict)
Output:
{1: 'Geeks', 2: 'For', 3: 'Python'}
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
del my_dict[3]
print(my_dict)
Output:
{1: 'Geeks', 2: 'For'}
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
my_dict1 = my_dict
print(my_dict1)
Output:
{1: 'Geeks', 2: 'For', 3: 'Geeks'}
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
my_dict.clear()
print(my_dict)
my_dict = {1: 'Geeks', 2: 'For', 3:'Geeks'}
z = len(my_dict)
print(z)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4