How to Change Value in Python Dictionary?

By Hardik Savani October 30, 2023 Category : Python

Hi Friends,

Now, let's see post of how to change value in python dictionary. I explained simply step by step how to replace value in dictionary python. we will help you to give an example of python dictionary change value. This example will help you python dictionary replace value example. Here, Create a basic example of how to change value in dictionary python.

There are several ways to change item values from a dictionary in python. i will give you two examples using update() and using key in python.

So, without further ado, let's see simple examples:

Example 1:

main.py

user = {
  "ID": 1,
  "name": "Hardik Savani",
  "email": "hardik@gmail.com"
}
  
# Update Item from dictionary
user["email"] = "hardik_update@gmail.com"
  
print(user)

Output:

{
 'ID': 1,
 'name': 'Hardik Savani',
 "email": 'hardik_update@gmail.com'
}

Example 2:

main.py

user = {
  "ID": 1,
  "name": "Hardik Savani",
  "email": "hardik@gmail.com"
}
  
# Update Item from dictionary
user.update({"email": "hardik_update@gmail.com"})
  
print(user)

Output:

{
 'ID': 1,
 'name': 'Hardik Savani',
 "email": 'hardik_update@gmail.com'
}

I hope it can help you...

Tags :
Shares