Variables and Data Types in Python
Give your data a name, and let Python remember it for you
- create a variable with the
=sign, - use the four core types:
int,float,str, andbool, - 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
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).