2. Data Types and Operators
2.2 Numbers and strings
Highlights & notes
Select lesson text to highlight it, or tap Add note.
Bookmarks
Bookmark a lesson to see it here.
Numbers are for maths. Strings are just letters in quotes, like a name tag.
- 7 is a number: you can add it.
- "7" is text: it is a picture of 7.
- Text + text glues the words together.
Thumb rule: Quotes make it text. No quotes, it's a number.
Watch it run · 1
print(7 + 7)14
Watch it run · 2
print("7" + "7")77
Every value in Python has a type. The type decides what you can do with it: you can add numbers, but you join text.
int: whole numbers, such as12rowsfloat: decimal numbers, such as4.75MBstr: text in quotes, such as"orders.csv"bool:TrueorFalseNone: no value at all (missing)
Keep IDs like "007" as text. As a number, 007 would lose its leading zeros and become 7.
Same digits, different types
12→ int, so12 + 1is13"12"→ str, so"12" + "1"is"121"12.0→ float, so12.0 + 1is13.0
Use type(value) when you’re unsure of a value’s type. type("7") is str, not int.
How it fits together
- int · 12
- str · "007"
- bool · True
Step through the code
Python
row_count = 12batch_id = "007"is_valid = Trueloaded_at = Noneprint(type(row_count).__name__, type(batch_id).__name__)print(type(is_valid).__name__, type(loaded_at).__name__)
Output
int str bool NoneType
Practice in Python ✓ Solved
Print the type names of size_mb and file_name on one line.
Expected output
float str
Reference solution
size_mb = 2.5
file_name = "orders.csv"
print(type(size_mb).__name__, type(file_name).__name__)
Question 1 · Easy
What type is "Noida"?
Question 2 · Medium
What type is 3.0?
Question 3 · Hard
What does print(type(None).__name__) show?
Key takeaways
Choose types that preserve the meaning and format of each field.
Save your progress
Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.
Start free Log in