Python Data Types
Every value in Python has a type.
The type is like the shape of a toy.
A ball rolls. A block stacks. A number adds. Text joins.
Python looks at the value and picks the type for you.
The main built-in types
You will meet these again and again.
int: whole numbers like 3
float: numbers with a dot like 3.5
str: text inside quotes
bool: True or False
list: a changeable row of items
tuple: a fixed row of items
dict: labeled drawers of pairs
set: a bag of unique items
Ask Python for the type
Use type() like asking, what kind of toy is this?
Numbers and text
Numbers are for counting and math.
Text is for names, messages, and words.
Do not mix them in math unless you change types on purpose.
Collections at a glance
A list is a toy box you can change.
A tuple is a sealed pack. Order stays. Contents stay.
A dict maps a key to a value, like a name tag to a locker.
A set keeps unique things and drops copies.
True-ish and false-ish values
In an if check, some values act like False.
Zero, empty text, empty list, and None act like False.
Most other values act like True.
Why types matter
Types tell you what tools work.
You can add 2 + 3.
You can join 'hi' + 'ya'.
You cannot add 2 + 'hi' without converting first.
Tip: Learn these core types well. Almost every program is built from them.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.