Python Numbers Explained (int, float, complex)
Python has different number types for different kinds of values.
The three main built-in numeric types are:
intfloatcomplex
If you are just starting Python, you will use int and float most of the time. This page explains what each type means, how to recognize it, and a few common mistakes beginners run into.
What this page covers
- Python has different number types for different kinds of values
- The main built-in numeric types are
int,float, andcomplex - Beginners mostly use
intandfloatfirst - This page explains what each type is and how to identify it
What is an int in Python?
An int is a whole number.
It does not have a decimal point.
Examples of integers:
05-3100
Use int for things like:
- counting items
- list indexes
- lengths
- whole-number math
apples = 5
temperature_change = -3
year = 2024
print(apples)
print(type(apples))
Output:
5
<class 'int'>
What is a float in Python?
A float is a number with a decimal point.
Examples:
3.142.0-0.5
Use float for values like:
- measurements
- averages
- prices
- division results
Even 2.0 is a float, because it includes a decimal point.
price = 19.99
average = 4.5
exact_two = 2.0
print(price)
print(type(price))
print(type(exact_two))
Output:
19.99
<class 'float'>
<class 'float'>
What is a complex number in Python?
A complex number has:
- a real part
- an imaginary part
In Python, the imaginary part uses j.
Examples:
2 + 3j5j-1 + 0j
Complex numbers are real Python number types, but they are much less common in beginner programs.
number = 2 + 3j
print(number)
print(type(number))
Output:
(2+3j)
<class 'complex'>
If you are new to Python, it is completely normal to focus on int and float first.
How to check a number type
Use the type() function to see the type of a value.
print(type(5))
print(type(3.14))
print(type(2 + 3j))
Output:
<class 'int'>
<class 'float'>
<class 'complex'>
This is very useful when you are debugging a program and want to see what kind of value you actually have.
Basic operations with numbers
You can do basic math with Python numbers:
- addition with
+ - subtraction with
- - multiplication with
* - division with
/
print(5 + 2)
print(5 - 2)
print(5 * 2)
print(5 / 2)
Output:
7
3
10
2.5
A few important rules:
- adding two
intvalues usually gives anint - using a
floatin an expression usually gives afloat - division with
/returns afloat
int and float together
Python can use int and float in the same expression.
When that happens, the result usually becomes a float.
print(5 + 2.0)
print(10 - 3.5)
print(4 * 1.5)
Output:
7.0
6.5
6.0
This is normal. Python keeps the decimal information instead of removing it.
Converting between number types
Use int() to convert a value to an integer.
Use float() to convert a value to a float.
print(int(3.9))
print(float(5))
print(int("10"))
print(float("3.14"))
Output:
3
5.0
10
3.14
Important: int(3.9) does not round. It removes the decimal part.
If you want rounding behavior, use round().
print(int(3.9))
print(round(3.9))
Output:
3
4
If you are converting text input into numbers, these guides can help:
Important beginner note about division
This is one of the most common beginner surprises:
print(10 / 2)
print(10 // 3)
Output:
5.0
3
Why?
/returns afloat//does floor division
So:
10 / 2gives5.010 // 3gives3
Use / when you want normal division.
Use // when you want a whole-number result.
Common beginner mistakes
Here are some common problems when working with numbers in Python.
1. Confusing numbers with strings from input()
The input() function returns text, not a number.
age = input("Enter your age: ")
print(type(age))
If the user enters 25, the type is still str, not int.
To fix this, convert the value:
age = int(input("Enter your age: "))
print(age)
print(type(age))
If the text cannot be converted, you may get a ValueError: invalid literal for int() with base 10.
2. Expecting int(3.9) to round up
This does not round:
print(int(3.9))
Output:
3
If you want rounding, use round() instead.
3. Forgetting that / returns a float
Many beginners expect this:
print(10 / 2)
to return 5.
But it returns:
5.0
That is correct behavior in Python.
4. Trying to mix strings and numbers with +
This causes an error:
age = 25
print("Age: " + age)
Python cannot join text and a number directly like that.
Fix it by converting the number to a string:
age = 25
print("Age: " + str(age))
Or use commas in print():
age = 25
print("Age:", age)
A related error is TypeError: can only concatenate str (not "int") to str.
When to use each number type
Use int when you need:
- counts
- positions
- indexes
- whole numbers
Use float when you need:
- decimal values
- measurements
- prices
- averages
Use complex only when you specifically need imaginary numbers.
For most beginner programs:
intis very commonfloatis also very commoncomplexis much less common
FAQ
What is the difference between int and float in Python?
An int is a whole number. A float is a number with a decimal point.
Why does Python return 5.0 instead of 5?
The / operator returns a float, even when the result looks like a whole number.
Does int() round a number?
No. int() removes the decimal part. Use round() if you want rounding.
What does j mean in a complex number?
In Python, j represents the imaginary part of a complex number.
Which number type should beginners focus on first?
Start with int and float. Complex numbers are usually needed later.