Python course menu
Python Data Types Explained: int, float, str, bool, None and More
Learn Python's basic data types with simple examples: integers, floats, strings, booleans, None, and collections. See how to check a type with type() and convert between types.
On this page
Every value in Python has a type. The type decides what the value is and what you can do with it. You can multiply two numbers, but you cannot multiply two names. You can make text uppercase, but not a number.
This lesson covers the types you will use every day.
Checking a type with type()#
The built-in type() function tells you the type of any value:
print(type(42))
print(type(3.14))
print(type("hello"))
print(type(True))<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>Ignore the word class for now; you will learn about classes later. The part in quotes is the type's name.
The core types at a glance#
Numbers: int and float#
An int is a whole number. A float has a decimal point.
apples = 12 # int
price = 35.5 # float
print(apples * price)
print(7 / 2) # division always gives a float
print(7 // 2) # floor division: drops the decimal part
print(7 % 2) # remainder
print(2 ** 10) # power426.0
3.5
3
1
1024Mixing an int and a float in a calculation gives a float, which is why 12 * 35.5 printed 426.0.
Python integers have no size limit, so you can work with very large numbers safely:
print(2 ** 100)1267650600228229401496703205376Text: str#
A string is text inside single or double quotes. Both work the same way; pick one style and be consistent.
language = "Python"
greeting = 'Hello'
print(greeting + ", " + language) # join strings with +
print(language * 3) # repeat a string
print(len(language)) # number of characters
print(language.upper())
print(language[0]) # first characterHello, Python
PythonPythonPython
6
PYTHON
PStrings are covered in depth in their own lesson. For now, remember: "5" is text, 5 is a number.
Yes or no: bool#
A boolean is either True or False (with a capital letter). You usually get booleans by comparing things:
age = 20
print(age >= 18)
print(age == 30)
print("py" in "python")True
False
TrueBooleans drive every decision your program makes, as you will see with if statements and loops.
No value: None#
None means "nothing here yet" or "no result". It is not 0, not False, and not an empty string. It is its own special value.
middle_name = None
print(middle_name)
print(middle_name is None)None
TrueCheck for None with is None, not == None. Both usually work, but is is the convention and is always correct.
Converting between types#
You can convert values with functions named after the type:
print(int("42") + 8) # str -> int
print(float("3.5")) # str -> float
print(str(100) + " points") # int -> str
print(int(9.99)) # float -> int (cuts off the decimals)
print(bool(0), bool(5)) # 0 is False, other numbers are True50
3.5
100 points
9
False TrueThis matters most when reading user input, because input() always returns a string, even if the user types a number.
Common mistakes#
Practice#
Practice exercise
Without running the code, write down the value and the type of each result:
a = 10 / 5
b = 10 // 3
c = "10" + "5"
d = int("10") + 5
e = 3 > 2Show hint
/ always produces a float. Adding two strings joins them. Comparisons produce booleans.
Show solution
You can confirm each one with print(x, type(x)).
Key takeaway#
Finished this lesson?