Lesson 3: Understanding Numbers in Python
Numbers form the backbone of programming, powering everything from simple calculations to advanced scientific operations. Python treats numbers as a flexible and powerful data type, making it easy for beginners to perform computations while still supporting advanced numerical work.
In this lesson, you will explore Python’s three primary numeric categories: integers, floating-point numbers, and complex numbers. Each type has unique characteristics that make Python a clean and reliable language for mathematics, analytics, and engineering tasks.
- Integer – Whole numbers such as
25or-100. - Float – Numbers with decimals like
2.3or45.67. - Complex – Numbers containing an imaginary part, for example
5jor3+2j.
3.1 Integers, Floating-Point & Complex Numbers
# Example of an integer
x = 25
print(x) # Output: 25
# Example of a floating point number
y = 2.3
print(y) # Output: 2.3
# Example of a complex number
a = 5j
b = 24j
print(a, b) # Output: 5j 24j
Use the type() function to check the exact number type stored in a variable:
x = 25
y = 2.4
a = 5j
print(type(a)) # complex
print(type(y)) # float
print(type(x)) # int
3.2 Performing Calculations in Python
Python supports all major arithmetic operations with clean and intuitive syntax. Here are several examples demonstrating addition, subtraction, division, and multiplication:
# Addition
x = 25
y = 36
print(x + y) # Output: 61
# Subtraction
y = 5
a = 2
print(y - a) # Output: 3
# Division
x = 6 / 3
print(x) # Output: 2.0
# Multiplication
a = 5 * 4
print(a) # Output: 20
3.3 Using max() and min() in Python
Python also provides two very useful built-in functions: max() and min().
These functions help you quickly find the largest and smallest numbers from a list or a group of values.
# Using max() and min() with direct values
largest = max(14, 55, 29, 3)
smallest = min(14, 55, 29, 3)
print(largest) # Output: 55
print(smallest) # Output: 3
# Using max() and min() with a list
numbers = [12, 45, 7, 89, 33]
print(max(numbers)) # Output: 89
print(min(numbers)) # Output: 7
The max() function returns the highest value,
while min() returns the lowest.
They are commonly used in data analysis, comparisons, and statistics.
Once you understand these basic operations, you can move on to more advanced techniques such as python round(),abs(),divmod() and so on.. Visit the next lesson on
Python Number Methods to continue learning.
Follow our learning channel for more tutorials:
FollowExercise
Create three variables — one integer, one float, and one complex number — and print their types using type().
Quick Quiz
Test Your Knowledge
Try our interactive Python Basics Quiz to reinforce your learning!