Data Types
📚 What are Data Types? Every value in Python has a type that tells the computer what kind of data it is and what operations make sense for it. Python has four main types: int (whole numbers like 5), float (decimal numbers like 3.14), str (text like 'hello'), and bool (True or False). Python detect…

Appy Says…
When you build an app you handle all kinds of data — names, ages, prices, true/false flags. Python needs to know what kind of thing you're storing so it can handle it correctly. Get this right and you'll avoid some of the most common beginner bugs.
What are Data Types?
A data type tells Python what kind of value a variable holds. Different types work differently — you can add two numbers together, but adding a number to some text gives an error.
- •int (integer) — whole numbers:
42,-7,1000 - •float (floating point) — decimal numbers:
3.14,9.99,-0.5 - •str (string) — text in quotes:
"hello",'Python' - •bool (boolean) — only two values:
TrueorFalse
Think of it like a FIFA player card
A player card has different kinds of data: the name is text (string), the overall rating is a whole number (int), the market value is a decimal (float), and the injured flag is yes or no (bool). Python stores each piece of data with the right type so it can handle it correctly.
How Types Interact
- •int + int = int:
5 + 3gives8 - •float + int = float:
3.14 + 1gives4.14 - •str + str = str (join):
"hello" + " world"gives"hello world" - •str + int = ERROR — you must convert:
"score: " + str(10) - •Check any type with
type(value)— Python tells you what it is
Real-World Examples
- •Instagram stores your
username = "pixel_dev"(str) andfollower_count = 4821(int) - •Spotify stores
track_duration = 3.47(float) for minutes and seconds - •A login system stores
is_logged_in = False(bool) — flips to True when you sign in - •Your bank app stores your balance as a float:
balance = 234.67
Key Facts
- •
type(x)tells you what typexis — brilliant for debugging - •Convert between types:
int("5")→ 5,str(42)→ "42",float("3.14")→ 3.14 - •True and False are capitalised —
true(lowercase) causes an error - •Division always gives a float in Python 3:
10 / 2gives5.0not5 - •For whole-number division use
//:10 // 3gives3
Watch Out: Mixing Types
One of the most common bugs is accidentally mixing types. "3" + 3 crashes because you can't add a string and an integer. Always convert first: int("3") + 3. When in doubt, check with type().
Remember
Python assigns types automatically (this is called dynamic typing). You don't write int score = 0 like some other languages — just score = 0 and Python figures it out. But the type still matters when you do operations!
What You Learned
- •The four basic types: int (whole number), float (decimal), str (text), bool (True/False)
- •Python assigns types automatically — you don't need to declare them
- •Use
type(x)to check what type something is - •Convert between types with
int(),float(),str() - •Mixing incompatible types causes an error — always convert first
Key Facts
- →
type(x)tells you what typexis — brilliant for debugging - →Convert between types:
int("5")→ 5,str(42)→ "42",float("3.14")→ 3.14 - →True and False are capitalised —
true(lowercase) causes an error - →Division always gives a float in Python 3:
10 / 2gives5.0not5 - →For whole-number division use
//:10 // 3gives3
Real-World Examples
Remember
Python assigns types automatically (this is called dynamic typing). You don't write int score = 0 like some other languages — just score = 0 and Python figures it out. But the type still matters when you do operations!
Quick Quiz
What type is 3.14?