Learning outcomes
By the end of this lesson you should be able to: name the four core data types you will meet most often; explain what is stored and what is reread when a variable is reused; predict whether an arithmetic expression yields an integer or a decimal; and convert comfortably between text and numbers without losing data.
Prerequisites
Lesson 1 (What a program is). You need to be comfortable with the idea that a single equals sign stores a value under a label, and that quoted text is printed literally while unquoted expressions are worked out first.
The big idea
Python is strongly typed but dynamically typed. Strongly means you cannot, for example, add a number to text without a deliberate conversion. Dynamically means you do not declare a variable's type in advance; Python infers it from the value you put in. That inference is the reason the same variable name can later hold a completely different kind of value — which is useful and occasionally a trap.
Why this matters before the syntax
Three types carry most of the weight in a first course: integers, floats and strings. A string is any text, marked by quote marks. An integer is a whole number without a decimal point, while a float is a number that has one — even a mathematically whole number like 10.0 counts as a float. The distinction is not cosmetic: Python will happily give you an exact answer with integers but a slightly rounded-internally one with floats, and it will refuse outright to combine a string with a number.
There is also a boolean type — True or False — which you will put to real use in the next lesson when you write conditions. For now, treat it as another kind of value a variable can hold.
The single rule that prevents the most beginner errors is this: a variable is re-read every time it is mentioned. It holds whatever was put into it last. If a program stores 5 as score, then later stores 9 as score, then prints score, it prints 9 — the earlier 5 is gone, not waiting somewhere to be recalled.
Worked example 1: a variable that changes
This is the read-last-value rule in action. Two print statements mention the same variable, and the second letter of the output differs because the value inside the box was replaced in between.
age = 19
print("Age:", age)
age = 20
print("Age now:", age)Age: 19
Age now: 20Read each line as an instruction, not a statement of fact. The first two lines store 19 and print it. The third line replaces the box's contents with 20. The fourth line re-reads the box — which now holds 20 — and prints that. Nothing about a variable is static; you are issuing commands to a machine that remembers only what you most recently told it.
Worked example 2: telling the types apart
The built-in type() function reports what kind of value is stored. It is the fastest way to see whether a number has a decimal point or a piece of text is actually text.
print(type(5))
print(type(3.14))
print(type("hello"))
print(type(True))<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>Notice the pattern: int for whole numbers, float for decimals, str for text, and bool for true/false. The type is not a label you assigned; Python derived it from how you wrote the value. The quote marks around hello are what made it a string — write hello without quotes and Python looks for a variable of that name instead, which is the lesson-1 NameError all over again.
Worked example 3: division is surprising
One division operator in Python behaves differently depending on how you write it. Understanding this now saves a whole class of off-by-one bug.
print(10 / 4)
print(10 // 4)
print(10 % 4)2.5
2
2A single slash always produces a float, even when the division is exact — so 10 / 4 is 2.5. The double slash is floor division, which rounds down to a whole number, so 10 // 4 is 2. The percent sign is the modulo operator, the remainder of that division, so 10 % 4 is 2. These three are the toolkit for the loop lesson, where you will repeatedly ask whether a number divides evenly or what is left over.
Worked example 4: converting between types
When you must join a number into a string, you convert explicitly. The names str(), int() and float() are your conversion tools.
print("The number is " + str(42))
print(int("7") + 1)The number is 42
8The first line maps out the classic error: you cannot concatenate a string with an integer using the plus operator, because the two types are incompatible. Wrapping the number in str() converts it into text the string can join with. The second line does the reverse — int("7") reads the digits as a number, so adding 1 gives 8 rather than appending the character to the text.
Common mistakes
Watch outAdding a string and a number. print('Age: ' + age) fails with a TypeError when age is an integer. The fix is either convert with str(age) or use a comma in print to let Python place the values side by side without combining their types.
Watch outConfusing floor division with exact division. Writing total // count thinking it divides exactly gives the rounded-down result. If you want decimals, use a single slash; if you want integer division, the double slash is deliberate.
Watch outForgetting a variable is re-read. Storing a new value does not leave the old one available. If you need to keep both, give them different names — a variable is a single box, not a pile.
Watch outAssuming a whole number is an integer. Python treats 10.0 as a float, so a value that looks whole may still behave like a decimal during division and in type checks.
Check your understanding
After the two lines age = 19 and age = 20 run, what does print(age) show, and why?
What is the value of 17 // 5, and how does it differ from 17 / 5?
Why does the expression "Age: " + age fail when age is 42, and what is the fix?
Multiple choice
Which value is stored as a float in Python?
What does print(10 % 3) output?
After score = 7 and then score = 9, what does score hold?
Which expression correctly joins a number into a sentence?
What type does type(3.14) report?
What is the output of print(7 // 2)?
Which of these is a valid variable name in Python?
Why is print(int("7") + 1) valid while print("7" + 1) is not?
Summary and next
A variable is a named box holding one value, re-read each time it is mentioned, replaced by each new assignment. The core types are int, float, str and bool, inferred from the value you store. Mixed-type operations are disallowed unless you convert explicitly, and division offers a decimal, a whole-number, and a remainder form.
Next: input, output and operators. This lesson stored values and told you what Python thinks they are; the next one lets you ask the user for a value, print results, and combine values with the full set of arithmetic and comparison operators.