Module 2 · Variables · Lesson 2 of 8
Variable names
You get to name your own boxes, but Python has a few firm rules. A name may contain letters, digits and underscores; it must start with a letter or an underscore — never a digit; and it can't be a word Python already reserves for itself, like class or if.
Legal names, and a few that aren't
✓ageplain and clear
✓user_nameunderscores are fine
✓_countmay start with _
✓x2digits allowed — just not first
✗2coolcan't start with a digit
✗my-varno hyphens or spaces
✗classit's a reserved keyword
Two more things to know. Names are case-sensitive: age, Age and AGE are three different boxes. And no spaces or punctuation — my-var looks like a subtraction, not a name.
Beyond the rules, there's a strong convention: use lowercase with underscores (user_name, total_price), and pick names that say what they hold. x is fine for a quick sum; days_left is far kinder to the next person who reads your code — usually you.