Skip to main content
Albero Academy

Variables

Name and store values, understand how Python names reference objects, and follow the naming conventions professionals use.

Fundamentals12 min

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

assigning values
name = "Aanya" # a string
age = 23 # an integer
package = 7.5 # a float
is_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 assignment
x, y, z = 1, 2, 3
a = 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: total and Total are different names.
  • Convention: lower_snake_case for variables; UPPER_SNAKE_CASE for constants.
  • Names should say what they hold — student_count, not sc or x.

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 subtle but important idea
a = [1, 2, 3]
b = a # b references the SAME list as a
b.append(4)
print(a) # [1, 2, 3, 4] — a changed too!
# For a truly separate copy:
c = a.copy()

Key takeaways

  1. 01A variable is a name that references a value; no type declaration is needed.
  2. 02Assign with = and reassign freely, even to a different type.
  3. 03Use descriptive lower_snake_case names; UPPER_SNAKE_CASE for constants.
  4. 04Names are references — assigning shares the object; copy mutable values when you need independence.

Finished this chapter?

Mark it complete to track your progress through Python.