Skip to content

Variables and Data Types in Python

Programming Python Difficulty 1/5

Beginning of the lesson

Variables and Data Types in Python

Give your data a name, and let Python remember it for you

Big Idea: A variable is a name that points to a value. You put a value into a variable once, and after that you can use the name again and again. Every value has a type — a number, some text, or a yes/no answer — and Python always knows which type it is.
By the end you will be able to:
  • create a variable with the = sign,
  • use the four core types: int, float, str, and bool,
  • change (reassign) what a variable holds,
  • check any value's type with type().

1. What is a variable?

A variable is a labelled box where Python stores a piece of information for you. You choose a name for the box, and you put a value inside it. Later, whenever you write the name, Python gives you back the value.

Analogy: Think of a jar with a sticky label. You write "sugar" on the label and pour sugar inside. Later you do not need to look in the jar — the label tells you what is there. A variable works the same way: the name is the label, and the value is what is stored.

You create a variable with the equals sign =. The name goes on the left and the value goes on the right:

name = "Ada"
age = 11
print(name)
print(age)

Output:

Ada
11

Read name = "Ada" as: "Let the name name point to the value Ada." The = here does not mean "equals" like in maths — it means "put this value into this name."

2. A picture of variables

name (the label) value (inside the box) type name "Ada" str age 11 int is_student True bool
Each variable is a name (the label) that points to a value. Every value has a type.

A name on the left points to a value on the right, and each value has a type. Here name holds text (a str), age holds a whole number (an int), and is_student holds a true/false answer (a bool).

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers