EN
Python - change dictionary item value
3 points
In this article, we would like to show you how to change dictionary item value in Python.
Quick solution:
xxxxxxxxxx
1
my_dictionary = {
2
"id": 1,
3
"name": "Tom",
4
"age": 25
5
}
6
7
my_dict["age"] = 28
In this example, we refer to the name of the dictionary key to change its value.
xxxxxxxxxx
1
my_dict = {
2
"id": 1,
3
"name": "Tom",
4
"age": 25
5
}
6
7
my_dict["age"] = 28
8
9
print(my_dict.items()) # [('id', 1), ('name', 'Tom'), ('age', 28)]
Output:
xxxxxxxxxx
1
dict_items([('id', 1), ('name', 'Tom'), ('age', 28)])