Python Data Types
The core kinds of values
In this lesson
Every value in Python has a type that decides what you can do with it. You’ll meet the core types and learn to check any value’s type with type().
Explain it like I’m 5
Values come in different shapes: text, whole numbers, decimals, true/false, and collections. The type is the shape, and the shape decides what operations make sense.
The everyday types
str— text, in quotes:"hi"int— whole numbers:42float— decimals:3.14bool—TrueorFalselist— an ordered collection:[1, 2, 3]dict— key→value pairs:{"a": 1}NoneType— the single valueNone, meaning ‘no value’
You’ll get a dedicated lesson on each of these. For now, just recognise them.
Checking a type with type()
type(value) tells you the type of any value. This is genuinely useful when debugging: a surprising bug is often a value that’s a different type than you assumed (for example, text "5" where you expected the number 5).
print(type("hi"))
print(type(5))
print(type(3.14))
print(type(True))
<class 'str'> <class 'int'> <class 'float'> <class 'bool'>
Print the type of three different values: a string, an int, and a float. Then try type([1, 2, 3]).
print(type("text"))
print(type(10))
print(type(2.5))
Pass any value to type() and print the result.
print(type("text"))
print(type(10))
print(type(2.5))
print(type([1, 2, 3]))
<class 'str'>
<class 'int'>
<class 'float'>
Why types matter
Operations depend on type. + adds numbers but joins strings, so 2 + 2 is 4 while "2" + "2" is "22". Mixing incompatible types ("2" + 2) raises a TypeError. Knowing the type tells you what’s allowed.
print(2 + 2)
print("2" + "2")
4 22
quantity = "5"
print(type(quantity))
number = int(quantity)
print(type(number), number + 1)
<class 'str'> <class 'int'> 6
Converting between types
You’ll constantly need to turn one type into another, and the tools are named after the target type: int() makes a whole number, str() makes text, float() makes a decimal, and bool() makes a True/False. So int("5") gives the number 5, and str(42) gives the text "42".
Conversion only works when it makes sense: int("hello") can’t become a number and raises an error. Recognising and handling those is its own skill — learn more about common errors here.
print(int("5") + 1)
print(str(42) + "!")
print(float("3.14"))
print(bool(""), bool("hi"))
6 42! 3.14 False True
What type is the value 3.0?
The decimal point makes it a float, even though it equals a whole number.
What does "2" + "3" produce?
Both are strings, so + joins them into "23" rather than adding.
Mini exercise (medium)
Create a variable holding the text "10", convert it to an integer, and print the integer plus 5.
Do it here. Finish the code below and press Run to try your answer right in the browser — no setup needed.
text = "10"
number = 0 # TODO: convert text to an integer
print(number + 5)
Use int("10"), store it, then add 5.
text = "10"
number = int(text)
print(number + 5)
assert number == 10, "number should be the integer 10"
print("✓ Correct!")