- Home
- /
- Python Numbers
Python Tutorial
Introduction
Python Data Types & Oper...
Python Strings
Python Lists
Python Tuples
Python Sets
Python Dictionaries
Conditional Statements
Python Loops
Python Functions
Python Modules
Python OOPS
Advanced Topics
File Handling
- Home
- /
- Python Numbers
Python Numbers
In Python, numbers are a built-in data type used for all kinds of calculations. They fall under three main types:
Integers – Whole numbers
Floats – Decimal numbers
Complex – Numbers with real and imaginary parts
Let’s go through each of them with unique examples.
Integer (int)
Integers are whole numbers — they can be positive, negative, or zero, but they never contain decimals.
temperature = -15
score = 0
people_count = 1203
print(type(temperature)) #
print(type(score)) #
print(type(people_count)) #
You can also use very large numbers — Python won’t limit you.
Float (float)
Float values represent numbers with decimal points, or written in scientific notation (exponential form).
weight = 72.5 # simple decimal
pi = 3.14159 # decimal with many digits
speed_of_light = 3e8 # 3 × 10^8
very_small = -1.2e-4 # -1.2 × 10^-4
print(type(weight)) #
print(type(speed_of_light)) #
print(type(very_small)) #
Even though floats can store large or small values, they aren’t always precise in mathematical calculations due to how computers handle decimals.
Complex (complex)
Python also supports complex numbers, which are made up of a real and an imaginary part. The imaginary unit is written as j
in Python (instead of i
like in mathematics).
z1 = 3 + 5j
z2 = -1.5j
z3 = 0 + 2j
z4 = 4 - 3j
print(type(z1)) #
print(type(z2)) #
print(type(z4)) #
You can even extract the real and imaginary parts:
print("Real part:", z4.real)
print("Imaginary part:", z4.imag)
Summary
Use
int
for whole numbers:42
,-99
,0
Use
float
for decimal values:3.14
,-2.5
,2.6e3
Use
complex
for numbers with imaginary parts:4 + 2j