A variable is a name that refers to a value. You store data in it, then use the name wherever you need the value. In Python you don't declare a type — you just assign, and the variable takes on whatever you give it.
What is a variable?
Think of a variable as a label stuck onto a value in memory. The label lets you refer to that value by a meaningful name.
Assignment
name = "Aanya" # a stringage = 23 # an integerpackage = 7.5 # a floatis_placed = True # a boolean# Reassign freely — the same name can point at a new value (even a new type)age = age + 1 # now 24# Multiple assignmentx, y, z = 1, 2, 3a = b = c = 0 # all three point at 0
Naming rules & style
- Start with a letter or underscore; then letters, digits, underscores. No spaces, no keywords.
- Case-sensitive:
totalandTotalare different names. - Convention:
lower_snake_casefor variables;UPPER_SNAKE_CASEfor constants. - Names should say what they hold —
student_count, notscorx.
Names are references
A Python variable doesn't "contain" the value — it references an object. Two names can reference the same object, which matters for mutable types like lists:
a = [1, 2, 3]b = a # b references the SAME list as ab.append(4)print(a) # [1, 2, 3, 4] — a changed too!# For a truly separate copy:c = a.copy()
Key takeaways
- 01A variable is a name that references a value; no type declaration is needed.
- 02Assign with = and reassign freely, even to a different type.
- 03Use descriptive lower_snake_case names; UPPER_SNAKE_CASE for constants.
- 04Names are references — assigning shares the object; copy mutable values when you need independence.
