Variables and Types: Boxes That Remember
variables and types
your code has amnesia
Last lesson, every calculation vanished the moment Python finished it. If you wanted the answer twice, you typed it twice.
Variables fix that — they're labeled boxes Python remembers. And once you store things, Python suddenly cares what KIND of thing you stored: a number behaves nothing like a piece of text.
- Variables let you name a value once and reuse it
- Python labels every value with a type — and types control what's allowed
watch a variable remember
Three lines. Watch price get reused without retyping 19.99.
type inspector
spot the type
store and reuse
Fill in your name as a string. Then add a line that prints greeting twice (one print per line, or one print with both).
build a tip calculator
Define bill (float), tip_percent (float), diners (int). Compute per-person total using only variables — no magic numbers in the formula. Store the result in per_person and print it.
the '3' + 5 trap
A learner writes:
teach it back
A friend who knows algebra but not programming asks:
Write a 2–4 sentence reply. Try to mention type, string, int, and why '3' + 5 fails.
boss: ship a receipt printer
Build a mini program that combines str, int, float, and bool. Customer name, item price, quantity, member flag → printed receipt line. Make 3 design calls:
compiled.
You just built a real receipt printer using int, float, str, and bool together — and dodged three TypeErrors that trip up most beginners. Variables are now your memory, and types are now your friend.
// spaced review schedule
Overview
The previous lesson computed values but forgot them. Now we store results in variables and discover that Python treats numbers, strings, and booleans differently. Introduces type errors as a feature, not a bug.
What you'll learn
- Assign values to variables and reuse them across multiple statements
- Identify int, float, str, and bool types and convert between them with int(), float(), str()
- Predict and fix common TypeError situations like '3' + 5
About this tutorial
This lesson is part of the Python Expert tutorial,
in the Become a Python Expert Today module.
Last updated May 4, 2026