π’ Operators
Operators are symbols used to perform operations on variables and values.
β 1. Arithmetic Operators:
Used to perform basic mathematical operations
+addition-subtraction*multiplication/division%modulus (remainder)**exponentiation (power)//floor division
arithmatic_operators.py
a = 10
b = 5
print("Addition:", a + b) # Output: 15
print("Subtraction:", a - b) # Output: 5
print("Multiplication:", a * b) # Output: 50
print("Division:", a / b) # Output: 2.0
print("Modulus:", a % b) # Output: 0
print("Exponentiation:", a ** b) # Output: 100000
print("Floor Division:", a // b) # Output: 2π° 2. Comparison Operators:
Used to compare values
==equal to!=not equal to>greater than<less than>=greater than or equal to<=less than or equal to
comparison_operators.py
a = 10
b = 5
print("Equal to:", a == b) # Output: False
print("Not equal to:", a != b) # Output: True
print("Greater than:", a > b) # Output: True
print("Less than:", a < b) # Output: False
print("Greater than or equal to:", a >= b) # Output: True
print("Less than or equal to:", a <= b) # Output: Falseβ 3. Logical Operators:
Combine conditional statements
andreturns True if both are trueorreturns True if one is truenotreverses the result
logical_operators.py
a = True
b = False
print("AND:", a and b) # Output: False
print("OR:", a or b) # Output: True
print("NOT:", not a) # Output: FalseLast updated on