In school, we learned about different types of numbers, such as whole numbers, decimals, and complex numbers. We use them in our daily lives to solve math problems and do calculations. In the same way, Python also uses numbers.
In Python, numbers are used to work with values like whole numbers and decimals. There are three major types of numbers in Python: integers, floating-point numbers and complex numbers. In this guide, you’ll learn everything you need to know about the different types of Python numbers and how to use them.
What is Python Numbers Data Type?
The Number type in Python is the numerical value stored in Python variables. These values can either be an integer, float or complex numbers. Let us recognise the Python numbers with the help of a simple example below.
a = 10
print(type(a)) b = 5.5 print(type(b)) c = 2 + 3j print(type(c)) |
Output
![]() |
The above example depicts the different types of Python numbers which are used in Python programming. We can know the types of these numbers using the predefined methods like type(). Let us know more about the types of Python numbers below.
How Many Types of Numbers In Python?
Python has three types of numbers: complex, integer, and float.
1. Python Integer
A Python integer is a whole number. The number can be zero, positive, or negative. You can use integers in Python to count things, calculate, or run loops. They are among the most commonly used number types in programming.
Example
Output
2. Python Float
In Python, floating-point numbers are values that contain a decimal point. They can be positive, negative, or even zero.
You can also write floats in scientific form using e or E, like 2.3e4 (which means 23000). You can create floating-point numbers by using a decimal or by calculating like division. Extra zeros at the end don’t count (for example, 7.0 is the same as 7).
But keep in mind, float values in Python are not always 100% exact because of how they are stored in memory. This may sometimes lead to small errors in calculations.
Example
Output
3. Python Complex Numbers
Complex numbers in Python have two components: a real part and an imaginary part.
The imaginary part is written using the letter j or J.
You can easily create complex numbers using the complex() function. The real part comes first, and the imaginary part is optional.
Complex numbers are represented as a + bj, where:
- a is the real part
- b is the imaginary part
Example
Output
How to Carry on Type Conversion in Python Numbers?
You can use built in functions to carry on type conversion from int(), float(), complex() and convert them into different types. If one operands is float we can convert it into integer using the built in method like int().
- int() is used to convert other python numbers into python integers
- float() is used to convert the python numbers i,e. Integer, complex from other types into python float.
- complex() will convert other python numbers such as integer, floats into complex numbers.
Let us understand it with the help of examples.
# Convert float to integer
a = 5.8 b = int(a) print(b) print(type(b)) # Convert int to float x = 7 y = float(x) print(y) print(type(y)) # Convert int to complex p = 4 q = complex(p) print(q) print(type(q)) |
Output
![]() |
Read More: Python Scripting: Automate Everything In Python Task For 2025
What Should You Keep in Mind When Choosing a Python Number?
When working with Python numbers, you should keep in mind some things for better results. Here are some recommendations that you should follow.
1. Select the Right Data Type
Use the right type of number in Python based on what you need. For whole numbers, use int. If you’re working with numbers that have decimals, use float.
When you need very accurate decimal values, especially for things like money or financial calculations, use the decimal module. And if you need to work with numbers that have both real and imaginary parts, use the complex type.
2. Avoid Floats for Accurate Calculations
Because floating-point numbers can be slightly inaccurate, it’s better to use the decimal module or fractions when you need exact decimal values and calculations.
3. Be Careful with Division
Make sure you know the difference between true division (/) and floor division (//). Use floor division when you want an integer result without any decimals.
Read More: Python String Methods: Perform Various Operations on String Values in Python
4. Convert Data Types Using Built-in Functions
You can use built-in functions like int(), float(), and complex() to change number types, making your code clearer and avoiding mistakes.
5. Use Math and NumPy for Calculations
For complex math, use the math module for basic functions and the NumPy library for advanced calculations, working with arrays, and linear algebra.
Learn Data Science with Generative AI Skills
Become a pro in Data Science with PW Skills Data Science with Generative AI Course. This 6 months course is powered by Generative AI to help you learn in demand skills based on a latest curriculum. You will learn about advanced tools and work on real time projects during this course with recorded as well as industry led live sessions.
Learn in the guidance of dedicated career mentors and build a strong portfolio for your data science career. If you are looking for a transition from data analyst to data scientist role then PW Skills is one of the best option you have to upskill yourself in the field of data science only at pwskills.com
Python Numbers and Its uses FAQs
Q1. How to print numbers in Python?
Ans: In Python, you can print numbers using the print() function. Here's an example:
print(5)
print(3.14)
print(2 + 3j)
Q2. How to Add Two Numbers in Python?
Ans: In Python, you can add two numbers by using the + operator. Start by storing the numbers in variables, and then apply the + operator to sum them.
Q3. What is float in Python?
Ans: Float numbers in Python have a decimal point. They can be positive, negative, or zero. You can write floats in scientific form with e or E, like 1.5e3 (which means 1500). Floats can be created either by using a decimal point or through calculations like division. Extra zeros at the end don’t matter (for example, 8.0 is the same as 8).
Q4. How to Swap Two Numbers in Python? Ans: To swap two numbers in Python, you can use a simple method that doesn’t require a temporary variable. Just use Python's multiple assignment feature.
xAns: To swap two numbers in Python, you can use a simple method that doesn’t require a temporary variable. Just use Python's multiple assignment feature.