Python Tutorial

Introduction

Edit Template

Python Tutorial

Introduction

Edit Template

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))   # <class 'int'>
print(type(score))         # <class 'int'>
print(type(people_count))  # <class 'int'>

				
			

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))         # <class 'float'>
print(type(speed_of_light)) # <class 'float'>
print(type(very_small))     # <class 'float'>

				
			

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))  # <class 'complex'>
print(type(z2))  # <class 'complex'>
print(type(z4))  # <class 'complex'>

				
			

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

Scroll to Top