Variable

A name that refers to a stored value, so you can reuse it by name.

You create a variable with the assignment operator =: the name on the left starts referring to the value on the right. The same name can be reassigned at any time, and it can hold any type of value — text, a number, a list, and so on.

Names may contain letters, digits, and underscores, cannot start with a digit, and are case-sensitive — age and Age are two different variables.

Example
age = 30          # bind the name "age" to the value 30
name = "Ada"      # a name can hold any type of value
age = age + 1     # reassign: "age" now refers to 31
print(name, age)
Output
Ada 31

Where this shows up in real Python

Variables are everywhere: storing user input, counting progress in a loop, holding an API response, or remembering a filename to write to later.

Commonly used Variable tools

A variable isn’t a class with methods, but a few built-ins inspect what a name points to:

  • type(value) — show what kind of object a name points to
  • isinstance(value, int) — check whether it points to a given type
  • del name — remove a name so it no longer points to anything

Related lessons

Related terms