Skip to content
Laviyx Learn

Try

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.

Beginner8 min readUpdated
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:

Python
print(type(42))
print(type(3.14))
print(type("hello"))
print(type(True))
Output
<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#

TypeNameExample valuesUsed for
intinteger0, 42, -7whole numbers, counts
floatfloating-point number3.14, -0.5, 2.0numbers with decimals
strstring"hi", 'Python'text
boolbooleanTrue, Falseyes/no answers
NoneTypenoneNone"no value"
listlist[1, 2, 3]ordered, changeable collections
tupletuple(1, 2)ordered, unchangeable collections
dictdictionary{"name": "Asha"}key–value pairs
setset{1, 2, 3}unique values

Numbers: int and float#

An int is a whole number. A float has a decimal point.

Python
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)       # power
Output
426.0
3.5
3
1
1024

Mixing 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:

Python
print(2 ** 100)
Output
1267650600228229401496703205376

Text: str#

A string is text inside single or double quotes. Both work the same way; pick one style and be consistent.

Python
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 character
Output
Hello, Python
PythonPythonPython
6
PYTHON
P

Strings 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:

Python
age = 20
print(age >= 18)
print(age == 30)
print("py" in "python")
Output
True
False
True

Booleans 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.

Python
middle_name = None
print(middle_name)
print(middle_name is None)
Output
None
True

Check 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:

Python
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 True
Output
50
3.5
100 points
9
False True

This 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:

Python
a = 10 / 5
b = 10 // 3
c = "10" + "5"
d = int("10") + 5
e = 3 > 2
Show hint

/ always produces a float. Adding two strings joins them. Comparisons produce booleans.

Show solution
VariableValueType
a2.0float
b3int
c"105"str
d15int
eTruebool

You can confirm each one with print(x, type(x)).

Key takeaway#

Finished this lesson?