Data types: numbers, text, and True/False
Code works with different kinds of values. A number, a piece of text, and a True/False answer are three different types — and each one behaves in its own way.
The big idea
The main data types are numbers, text (called strings), and True/False values (called booleans).
See it in code
Code works with different kinds of values. 100 is a plain number, but "Blaze" sits in quotes because it's text:
print(100)
print("Blaze")100 Blaze
The quotes are the whole difference: 100 is a number, "Blaze" is text. That's two of the three main types.
The third type is a yes-or-no value: True or False, called a boolean. No quotes, no counting — just one answer or the other:
is_hero = True
game_over = False
print(is_hero)
print(game_over)True False
True and False are booleans. Numbers, text, booleans — those are the three kinds a hero sheet is built from.
Here all three land on one hero sheet. name is text (a string), age is a whole number (an int), and is_brave is a boolean:
name = "Blaze"
age = 12
is_brave = True
print(name, "- text (a string)")
print(age, "- a whole number (an int)")
print(is_brave, "- True or False (a boolean)")Blaze - text (a string) 12 - a whole number (an int) True - True or False (a boolean)
The quotes around "Blaze" are what make it text. Take them off and Python would look for a box named Blaze. The type of a value decides what you can do with it.
Every value has a type. A score is a number, a player's name is text, and 'is the game over?' is a boolean. Knowing the type tells you what's allowed: you can add numbers, but you glue text together and flip booleans.
Try it yourself
Add health = 100 (a number) and title = "Knight" (text). Then try adding a number to text, like age + name — Python will complain, because you can't add two different types.
The common mistake
Mixing up "12" (text) and 12 (a number). "12" + "3" glues text into "123", but 12 + 3 adds to 15. The quotes change everything about how a value behaves.
What it unlocks
Knowing types helps you do math with operators, transform text with string methods, and store each value in a variable.