Operators

11. Operators

Operators are symbols used to perform operations with numbers and variables.

Arithmetic operators

OperatorMeaningExampleResult
+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/Division10 / 25.0
//Floor division10 // 33
%Remainder10 % 31
**Power2 ** 38

Example:


a = 10
b = 3

print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a % b)

Comparison operators

These operators compare two values and return True or False.

OperatorMeaning
==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

Example:

speed = 80

print(speed > 50)
print(speed == 80)
print(speed < 100)