
Basic Data Types in Python
Look at these two lines. The operator is the same, but the result is different:
Python 3.13print(10 + 5)15print("10" + "5")105
In the first case + added the numbers; in the second it glued two strings together. Python behaves differently because 10 and "10" are not the same thing to it: the first is a number, the second is text. Python attaches a type to every value, and it's the type that decides what an operation on that value means.
That's why mixing up types is a common source of beginner bugs: you add two values expecting 15 and get "105" instead, because the values were actually strings.
How to find out a value's type
If you're not sure what you're dealing with, you can ask for the type directly with the type() function.
Python 3.13print(type(42))<class 'int'>print(type(3.14))<class 'float'>print(type("Python"))<class 'str'>print(type(True))<class 'bool'>
In the output int is a whole number, float is a number with a fractional part, str is a string, bool is a boolean value (true or false). You don't declare the type up front: Python figures it out from what you wrote.
Python 3.13number = 42 # int — a whole number pi = 3.14 # float — a number with a fractional part name = "Python" # str — a string is_active = True # bool — a boolean value
What types exist in Python
Besides the four basic ones, Python has built-in types for collections and more specialized tasks. Here are the main categories:
In the next few chapters we'll cover numbers, strings, and booleans in detail, then move on to collections — lists, tuples, sets, and dictionaries. For now one idea is enough: every value has a type, and that type decides what you can do with the value.
Check your understanding
What does print("3" + "4") output?
