Data Types - Why Different Boxes?
3 / 15

Why Can't We Treat All Information the Same?

"There are different kinds of information in the world, and Python must know which kind is inside a box before it knows how to act on it."

The Three Fundamental Types

String (str)

Text & Characters

"Hello World"

Anything wrapped in quotes. Even "25" in quotes is treated as text, not a quantity!

Integer (int)

Whole Numbers

42

Whole numbers without quotes or decimals. Ready for arithmetic: +, -, *, /.

Boolean (bool)

Truth Switch

True / False

Only two possible values: True or False. Powers every decision in code.

Why Types Matter: Operation Tester

Notice how the + symbol changes meaning—or raises an error—depending on the data types involved:

Click an expression above to see how Python evaluates its types!
Mental Model: Types define the laws of physics for your data. Adding two numbers performs arithmetic (5 + 3 → 8), while adding two strings glues them together end-to-end ("5" + "3" → "53").

Type Conversion (Casting): The Type Transfigurer

When you have text like "25" and need to do math—or have a number like 25 and want to glue it into a sentence—you use casting functions (int(), str(), bool()) to transform its type:

Interactive Type Casting Transfigurer

Select a casting spell above to see how int() and str() transform data!
CHEAT SHEET Type Checking & Casting Reference (type(), int(), str()) + Explore
# Inspect any value's type using type()
type("hello")   # <class 'str'>
type(42)        # <class 'int'>
type(True)      # <class 'bool'>

# Convert between types explicitly
age_num = int("25")              # "25" (str) -> 25 (int)
msg = "Score: " + str(100)       # 100 (int)  -> "100" (str)
Crimson Rose
Card 3 Takeaway (Crimson Rose Unlocked!): Whenever Python complains with a TypeError, ask yourself: "What type is inside each box right now, and do I need int() or str() to bridge them?"
Data types tell Python whether '25' is text to read or a number to count. Type casting (int(), str()) converts one into the other.
Wizard Guide