How to Update Variable Values in Python

In Python, variables are dynamic, meaning you can reassign or update their values at any time. When you assign a new value, Python simply overwrites the previous one:
score = 50
print(score) # Output: 50
score = 75
print(score) # Output: 75
Key Insight:
Python variables can change both their value and even their data type during program execution. This flexibility is one of Python’s strengths for rapid development and prototyping.
Try It Yourself
Let’s practice both assignment patterns:
Step 1: Same Value Assignment
x = y = z = 5
print(x, y, z)
Step 2: Multiple Value Assignment
a, b, c = 1, 2, 3
print(a, b, c)
Output:
5 5 5
1 2 3
Experiment Further:
- Try changing variable types:
value = 10
followed byvalue = "hello"
- Mix different data types in multiple assignment:
name, age, height = "Alice", 25, 5.7
Now that you’re comfortable updating variables, get ready to learn a clever Python trick in How to Swap Variable Values in Python — you’ll discover how to swap two variables in a single line of code!