Basics
Variables
Assignment binds a name to a value. Once bound, the name can be used anywhere that value is needed.
Source
message = "hi"
print(message)Output
hiAssignment can rebind the same name to a different value. The name is not permanently attached to the first object.
Source
message = "hello"
print(message)Output
helloAugmented assignment reads the current binding, computes an updated value, and stores the result back under the same name.
Source
count = 3
count += 1
print(count)Output
4Notes
- Python variables are names bound to objects, not boxes with fixed types.
- Rebinding a name is normal.
- Use augmented assignment for counters and accumulators.
See also
- related: Values
- next depth: Mutability
- related: Object Lifecycle
- related: Constants
Run the complete example
Expected output
hi
hello
4
Execution time appears here after you run the example.