Skip to content
Home » Numbers

Numbers

Here is a clear, complete, and exam-ready explanation of the Numbers Data Type in Python, perfect for BCA/MCA/B.Tech students.


Numbers Data Type in Python

Numbers are one of the most commonly used data types in Python.
Python supports three native numeric data types:

  1. int – Integer
  2. float – Floating point numbers
  3. complex – Complex numbers

These data types allow Python to perform mathematical and scientific computations efficiently.


1. Integer (int)

Integers are whole numbers without decimal points.
They can be:

  • Positive
  • Negative
  • Zero

Examples:

a = 10
b = -25
c = 0

Key Features:

  • No limit on size (Python automatically enlarges integers based on memory).
  • Supports binary, octal, and hexadecimal formats.

Different formats of integers:

x = 0b1010     # binary   → 10
y = 0o12       # octal    → 10
z = 0xA        # hex      → 10

2. Float (float)

Floats are real numbers with decimal points.

Examples:

pi = 3.14
height = 5.67
temperature = -12.5

Features of float:

  • Represented using double precision (64-bit).
  • Can also represent scientific notation.

Scientific notation:

x = 1.5e3      # 1.5 × 10³ → 1500.0
y = 2.5e-2     # 2.5 × 10⁻² → 0.025

3. Complex Numbers (complex)

Python supports complex numbers natively.
A complex number is of the form:

a + bj

Where:

  • a = real part
  • b = imaginary part
  • j = √(-1) (Python uses j instead of i)

Example:

c1 = 2 + 3j
c2 = -1 - 4j

Accessing parts of a complex number:

c = 5 + 6j
print(c.real)    # 5.0
print(c.imag)    # 6.0

4. Type Checking

You can check the type of any number using type():

type(10)       # int
type(10.5)     # float
type(2+3j)     # complex

5. Type Conversion (Casting)

Python allows conversion between numeric types.

int → float:

float(10)      # 10.0

float → int:

int(12.98)     # 12   (fraction dropped)

int/float → complex:

complex(5)       # 5 + 0j
complex(3.5)     # 3.5 + 0j
complex(3, 4)    # 3 + 4j

6. Arithmetic Operations with Numbers

Python supports all arithmetic operations on numeric types:

a = 10
b = 3

print(a + b)    # 13
print(a - b)    # 7
print(a * b)    # 30
print(a / b)    # 3.333
print(a // b)   # 3 (floor division)
print(a % b)    # 1 (modulus)
print(a ** b)   # 1000 (power)

7. Using Numbers with Math Library

Python provides the math module for advanced mathematical operations.

Example:

import math
print(math.sqrt(25))
print(math.pow(2, 3))
print(math.pi)
print(math.sin(1))

8. Important Points About Numeric Types

  • Python automatically detects number type.
  • Integers have no limit in size.
  • Floats use IEEE 754 double precision.
  • Complex numbers are built-in (unique to Python compared to many languages).
  • A number’s type decides how it behaves in expressions.

9. Examples Demonstrating Numbers

a = 15            # int
b = 3.5           # float
c = 2 + 4j        # complex

print(a + b)      # float result: 18.5
print(a + c)      # complex result: 17 + 4j
print(type(a / 5))  # always float

Summary Table: Python Number Types

TypeDescriptionExample
intWhole numbers10, -5, 0
floatDecimal/real numbers3.14, -7.2
complexa + bj numbers2+3j, -1+4j