Text vs Numbers: Types
Why "5" and 5 are not the same thing
Every value in Python has a type — a kind. The two types you'll meet first are:
- Text, called a string. Strings are always wrapped in quotes:
"hello","5","Sam". - Whole numbers, called integers (or int for short). These have no quotes:
5,42,0.
There are also numbers with a decimal point, like 3.14, called floats. We'll use those soon too.
Why the difference matters
The quotes change everything. Look carefully:
print(5 + 3)
print("5" + "3")The first line shows 8 — real math, because 5 and 3 are numbers.
The second shows 53 — because "5" and "3" are text, and adding text just sticks it together end-to-end. That sticking-together is called joining (or concatenation, a fancy word you can forget).
Checking a type
You can ask Python what type something is with type:
print(type(5))
print(type("5"))The first reports it's an int; the second reports it's a str (Python's short name for string).
Tip: If a value has quotes around it, it's text — even if it looks like a number. "100" is text; 100 is a number you can do math with.
Your turn
Run the code and watch how the same symbols behave differently for numbers and text.
Press “Run code” to see the result.
Quick check
Q1 What does "5" + "3" produce in Python?
Q2 Which of these is a number (integer), not text?
Want to save your progress? It's free.
Create a free account