EN
Python - add dictionary items
3 points
In this article, we would like to show you how to add dictionary items in Python.
In this example, we add item to the dictionary by using new index key and assigning a value to it.
xxxxxxxxxx
1
my_dict = {
2
"id": 1,
3
"name": "Tom"
4
}
5
6
my_dict["age"] = 25
7
8
print(my_dict.items()) # [('id', 1), ('name', 'Tom'), ('age', 25)]
Output:
xxxxxxxxxx
1
dict_items([('id', 1), ('name', 'Tom'), ('age', 25)])