Numbers are one of the most commonly used data types in Python. They are used to store numeric values and perform mathematical calculations. Python supports three main types of numbers: Integer, Float, and Complex.
Understanding these number types is important for performing calculations, financial analysis, data processing, and many real world applications.
INTEGER (INT)
An integer is a whole number without any decimal point. It can be positive, negative, or zero.
Examples:
age = 25
temperature = -5
total_students = 100
Integers are used for counting values, indexing, and performing basic arithmetic operations.
Example of integer calculation:
x = 10
y = 5
print(x + y)
Output will be 15.
FLOAT
A float is a number that contains a decimal point. It represents real numbers and is used when precision is required.
Examples:
price = 99.99
average = 85.5
height = 5.8
Floats are commonly used in financial calculations, percentages, and measurements.
Example:
a = 10.5
b = 2.5
print(a * b)
Output will be 26.25.
COMPLEX
A complex number contains a real part and an imaginary part. In Python, the imaginary part is written using the letter j.
Examples:
z = 3 + 4j
number = 2 – 5j
Complex numbers are mostly used in advanced mathematics, engineering, and scientific calculations.
You can also check the type of any number using the type function.
Example:
x = 10
print(type(x))
This will display that x is an integer.
TYPE CONVERSION BETWEEN NUMBERS
Python allows you to convert one number type into another.
Example:
x = 10
y = float(x)
This converts the integer 10 into a float 10.0.
Similarly, you can convert float to int using int() function.
WHY NUMBER TYPES ARE IMPORTANT
Understanding number types helps you perform accurate calculations and choose the correct data type for your program. Using the right numeric type improves performance, clarity, and correctness in your applications.
Mastering integers, floats, and complex numbers builds a strong foundation for mathematical and logical programming in Python.