Skip to content
On this page

Operators

Arithmetic Operators:

Python supports standard arithmetic operators like +, -, *, /, % (modulo), and ** (exponentiation).

python
# Arithmetic operators
a = 10
b = 3

sum_ab = a + b
diff_ab = a - b
product_ab = a * b
quotient_ab = a / b
remainder_ab = a % b
power_ab = a ** b

Comparison Operators:

Comparison operators are used to compare values. They return a boolean value (True or False) based on the comparison.

python
# Comparison operators
a = 10
b = 3

is_equal = a == b
is_not_equal = a != b
is_greater_than = a > b
is_less_than = a < b
is_greater_than_or_equal = a >= b
is_less_than_or_equal = a <= b

Logical Operators:

Logical operators are used to combine multiple conditions and evaluate their truth values.

python
# Logical operators
x = True
y = False

result_and = x and y
result_or = x or y
result_not = not x

Assignment Operators:

Assignment operators are used to assign values to variables.

python
# Assignment operators
x = 10
y = 5

x += y  # Equivalent to x = x + y
x -= y  # Equivalent to x = x - y
x *= y  # Equivalent to x = x * y
x /= y  # Equivalent to x = x / y
x %= y  # Equivalent to x = x % y