Arithmetic operators#

Arithmetic operators perform mathematical operations on numeric variables, including addition, subtraction, multiplication, division, exponentiation, and floor division.

See definition:

Operation

Operator

Examples

Multiplication

*

5 * 2 = 10

Division

/

10 / 2 = 5

Addition

+

7 + 3 = 10

Subtraction

-

10 - 3 = 7

Floor Division

//

10 // 3 = 3

Modulo

%

10 % 3 = 1

Power

**

5 ** 2 = 25

Examples

# Define two variables
a = 7
b = 3
# multiplication
c = a * b
print (f'Multiplication: {c}')
Multiplication: 21
# division
c = a / b
print (f'Division: {c}')
Division: 2.3333333333333335
# addition
c = a + b
print (f'Sum: {c}')
Sum: 10
# subtraction
c = a - b
print (f'Subtraction: {c}')
Subtraction: 4
# floor division - it rounds a given number down to the nearest integer that is less than or equal to the original number
c = a // b
print (f'Floor Division: {a // b}')
Floor Division: 2
# modulo - it calculates the integer remainder of dividing the first number (dividend) by the second number (divisor)
c = a % b
print (f'Modulo: {c}')
Modulo: 1
# a to the power b -  two asterisks (**) raise a number to a specified exponent
c = a ** b
print (f'Power: {a ** b}')
Power: 343