Operators in Python

Operators are special symbols in Python that carry out arithmetic or logical computation. The value that the operator operates on is called the operand. Operators are the constructs which can manipulate the value of operands.

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division.

# Addition (x + y)
# Subtraction (x - y)
# Multiplication (x * y)
# Division (x / y)
# Modulus (x % y)
# Exponentiation (x ** y)
# Floor division (x // y)

Comparison Operators

Comparison operators are used to compare values. It either returns True or False according to the condition.

# Equal (x == y)
# Not equal (x != y)
# Greater than (x > y)
# Less than (x < y)
# Greater than or equal to (x >= y)
# Less than or equal to (x <= y)

Logical Operators

Logical operators are the and, or, not operators. They are used to combine conditional statements.

# and - Returns True if both statements are true (x > 3 and x < 10)
# or - Returns True if one of the statements is true (x > 3 or x == 3)
# not - Reverse the result, returns False if the result is true (not(x > 3 and x < 10))