Variables in Python
A variable is a name that points to a value stored in memory. In Python you create one simply by assigning a value with = — no separate declaration step, no type keyword required first.
The name itself doesn't hold the value directly; it's a label pointing at an object. That's why the same name can be reassigned to a completely different type later — a variable is just a pointer, not a fixed-type box, as you already saw briefly in the very first example of this course.
Choose a name
Pick an identifier following the rules from Keywords & Identifiers — letters, digits, underscores, starting with a letter or underscore.
Bind it with =
name = value creates the value first, then points the name at it.
Python builds the object first
The right-hand side is fully evaluated before the assignment happens, so score = score + 5 computes the new total using the OLD value of score.
Reading it later follows the pointer
Using the variable anywhere afterward just retrieves whatever value it currently points to.
Reassigning points elsewhere, it doesn’t edit
A new = doesn’t change the old object in place — it points the name at a new object entirely, of any type.
score = 10print(score) score = score + 5print(score) score = "ten"print(score)Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.