🔢 Python Numbers – Int, Float, Complex Explained Simply | TechTown.in

In Python, numbers are more than just digits — they’re data types with different behaviors and use-cases. Whether you’re building a calculator app, analyzing datasets, or writing logic-based programs, you’ll be using Python numbers everywhere.

In this guide, we’ll break down Python’s numeric data types: int, float, and complex, with examples and practical tips. Let’s start counting!


🧮 What Are Numbers in Python?

Python has three main types of numbers:

Data TypeDescription
intWhole numbers (positive/negative)
floatDecimal numbers
complexNumbers with real and imaginary parts

You can create a variable and Python will automatically assign the type based on the value:

x = 10       # int
y = 3.14     # float
z = 2 + 3j   # complex

🔹 int – Integer Numbers

These are whole numbers — without decimals.

x = 100
print(type(x))  # <class 'int'>

Integers can be positive, negative, or zero.


🔹 float – Decimal (Floating Point) Numbers

These are numbers that contain a decimal point.

price = 199.99
print(type(price))  # <class 'float'>

They are used when precision is required — for example in billing, scientific calculations, or measurements.


🔹 complex – Complex Numbers

A number with both real and imaginary parts, written as a + bj.

z = 5 + 4j
print(type(z))  # <class 'complex'>

Mostly used in engineering, machine learning, or scientific simulations.


🔄 Type Conversion in Python (Casting)

You can convert between number types using built-in functions:

# Convert int to float
x = float(5)   # 5.0

# Convert float to int
y = int(3.8)   # 3 (decimal is dropped)

# Convert int to complex
z = complex(10)  # 10 + 0j

Use type casting when:

  • You want to perform operations between different types
  • You need to control precision
  • You’re accepting numeric input as strings from a user

🔍 Check Type with type()

Use type() to check the type of any number:

x = 7.5
print(type(x))  # <class 'float'>

➕ Arithmetic Operations with Numbers

Python supports standard math operations with numbers:

x = 5
y = 2

print(x + y)   # Addition → 7
print(x - y)   # Subtraction → 3
print(x * y)   # Multiplication → 10
print(x / y)   # Division → 2.5
print(x ** y)  # Exponentiation → 25

Use these with both integers and floats.


📌 Summary – Python Number Types

TypeExampleDescription
int10Whole number
float3.14Decimal number
complex1 + 2jComplex number (real + imag)

🧠 Quick Tips

  • ✅ Python uses dynamic typing – no need to declare types manually
  • ✅ Use int(), float(), and complex() for casting
  • ❌ Avoid converting float to int if precision is important
  • ✅ Check types with type() while debugging

🏁 Final Thoughts

Understanding Python numbers is foundational to coding. Whether you’re building logic, handling user input, or working with data — knowing how to work with int, float, and complex will keep your code accurate and powerful.


📘 Explore more beginner-friendly Python tutorials at TechTown.in