Skip to content

Variable

In one line

A variable is a named reference to a value stored in memory, created with the = assignment operator.

In simple words

A variable in Python is a name that points to a value. You create one with the assignment operator =: age = 25 creates a variable named age that holds the value 25.

Python variables are dynamically typed — the same variable can hold different types at different times. You do not declare the type; Python infers it from the value. Variable names must start with a letter or underscore and cannot be keywords.

Variables are more like labels than boxes. The variable name is a label attached to a value object in memory. When you reassign, the label points to a new object.

Example

python
name = "Alice"
age = 30
pi = 3.14159

print(name, age, pi)

# Reassignment changes the reference
age = "thirty"
print(age)  # "thirty"

Variables are created with = and can be reassigned to any type.

Common confusions

  • Confused with: constant

    The difference: A variable can be reassigned. A constant (by convention, ALL_CAPS names) should not be changed, though Python does not enforce this.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary