Learn Python
Lesson 1 - Introduction To Python
Lesson 3 - Control Flow
Lesson 4 - Functions
Lesson 5 - Basic Data Structures
Lesson 6 - Exception Handling
Lesson 7 - Modules And Packages
Lesson 8 - Basic String Operations
Lesson 9 - Object-Oriented Programming (OOP)
Just like in mathematics, Python allows you to perform various mathematical operations such as addition, subtraction, multiplication, division, and more.
Here are the basic operators in Python:
Operator | Description | Example |
---|---|---|
+ | Addition | 5 + 2 = 7 |
- | Subtraction | 5 - 2 = 3 |
* | Multiplication | 5 * 2 = 10 |
/ | Division | 5 / 3 = 1.67 |
% | Modulo (Remainder) | 5 % 3 = 2 |
** | Exponentiation (Power) | 5 ** 3 = 125 |
// | Floor Division (Integer Div) | 5 // 2 = 2 |
These operators are fundamental in Python and are used extensively for mathematical computations.
Let's see how we can use these mathematical operators in Python:
print(5 + 7) # Addition: Outputs 12 print(5 - 2) # Subtraction: Outputs 3 print(5 * 2) # Multiplication: Outputs 10 print(5 / 3) # Division: Outputs approximately 1.67 print(5 % 3) # Modulo (Remainder): Outputs 2 print(5 ** 3) # Exponentiation (Power): Outputs 125 print(5 // 2) # Floor Division (Integer Div): Outputs 2
These examples demonstrate how each operator works in Python and what results you can expect. Understanding these operations is crucial for performing calculations and manipulating data in Python.