Python: assignment is not an equation
First evaluate the right side, then bind the name on the left to that value.
| Line | Value of x afterwards |
|---|---|
| x = 2 | 2 |
| x = x + 3 | 5 |
One worked example
- x = 2The name x now refers to 2.
- x = x + 3The right side evaluates 2 + 3; x then refers to 5.
Watch out: In Python, = assigns and == compares. This example uses integers; shared mutable objects require further care.
Goal, prerequisites and card origin
What you will learn: Track a variable through successive assignments.
What you need first: A variable as a name for a value; addition.
An original PEAZIT working card. Independent expert review and effectiveness testing have not yet taken place. · v1
Show connections
First evaluate the right side, then bind the name on the left to that value.