Standard Arithmetic Operators ( + - * / )
Standard arithmetic functions work as normal in Python. Take note that multiplication is achieved using an asterisk * .
a = 5
b = 3
result = a + b
result = a - b
print(result) #The output will be 2.
result = a * b
print(result) #The output will be 15.
a = 10
b = 2
result = a / b
print(result) # The output will be 5.0.
Arithmetic operators are used to perform
calculations.
The arithmetic operator
is used to perform multiplication.
What is the outcome of 20 - 10?
Modulo (%)
The modulo operator is used to find the remainder of a division. For example:
a = 15
b = 4
result = a % b
print(result) #The output will be 3.
What is the result of 7 % 2?
Floor division
Floor division (also known as integer division) is performed using the double forward slash operator //.
It divides one number by another and returns the quotient rounded down to the nearest whole number.
x = 10
y = 3
result = x // y # Floor division of 10 by 3
print(result) # Output: 3
What is the result of 10 // 3?
Exponentiation (**)
The exponentiation operator is used to raise a number to a power.
Example:
a = 2
b = 3
result = a ** b
print(result) #The output will be 8.
What is the result of 2 ** 4?
Activity Complete