Arithmetic Operators:
+/// (returns the quotient)% (returns the remainder)* (raises to the power)a = 10
b = 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a / b) # 3.333...
print(a // b) # 3
print(a % b) # 1
print(a ** b) # 1000
Comparison Operators:
==!=><>=<=x = 5
y = 10
print(x == y) # False
print(x != y) # True
print(x > y) # False
print(x < y) # True
print(x >= y) # False
print(x <= y) # True
Logical Operators:
andornota = True
b = False
print(a and b) # False
print(a or b) # True
print(not a) # False
Assignment Operators:
=+===/=%=//=*=x = 5
x += 3 # Equivalent to x = x + 3
print(x) # 8
Identity Operators:
is - True if the operands are identical (refer to the same object)is not - True if the operands are not identicala = [1, 2, 3]
b = a
print(a is b) # True
print(a is not b) # False
Membership Operators:
in - True if value/variable is found in the sequencenot in - True if value/variable is not found in the sequencemyList = [1, 2, 3, 4, 5]
print(3 in myList) # True
print(6 not in myList) # True
These are fundamental operators in Python, and they are used extensively in writing Python code. Understanding how these operators work is crucial for effective programming in Python.