Python Variables
In this post
How names are bound to values in Python, and why nothing is declared.
How names are bound to values in Python, and why nothing is declared.
A name is a label
A variable in Python is a name bound to an object. There is no type to declare and no memory to reserve — the name simply points at a value, and can be pointed at another one later.
name = "Ada"
age = 36
age = age + 1
print(name, age)
Output:
Ada 37
Several at once
Python unpacks the right-hand side across the names on the left, which is why swapping two values needs no temporary.
x, y = 1, 2
x, y = y, x
print(x, y)
Output:
2 1
Next
Carry on to the next tutorial in the rail — it picks up where this one leaves off.
PythonVariables