Arithmetic, Logical, and Comparison Operators

Python includes a variety of operators that allow you to manipulate and compare data.

Arithmetic Operators

Operator Description Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ True division a / b
// Floor division a // b
% Modulus (remainder) a % b
** Exponentiation a ** b

Comparison Operators

They return boolean values (True or False):

Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
a = 10
b = 5
print(a > b)  # True

Logical Operators

Used to combine boolean expressions:

Operator Meaning
and Logical AND
or Logical OR
not Logical NOT
age = 20
is_adult = age >= 18 and age < 65