Master AI & Build your First Coding Portfolio with SkillReactor | Sign Up Now

Lesson 2 - Basic Python Syntax

2.2 Basic Operators

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:

OperatorDescriptionExample
+Addition5 + 2 = 7
-Subtraction5 - 2 = 3
*Multiplication5 * 2 = 10
/Division5 / 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.

Example Usage:

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.