Module 2 · Variables · Lesson 1 of 8
Variables — data-shaped boxes
So far your values have been throwaway — printed once and gone. A variable lets you keep one: it's a named box that stores a value so you can use it again later, or change it as your program runs.
One box, any kind of data
data
25
type: intTwo things make a variable: a name on the outside and a value inside. And here's the “data-shaped” part — Python doesn't lock a box to one type. The same name can hold an integer now, a string later, a boolean after that. The box quietly takes the shape of whatever you put in it.
That flexibility is powerful, and just occasionally a trap (a box you thought held a number might now hold text). For the next few lessons we'll keep it simple: how to name a box, how to fill it, and how to use what's inside.