In Python (programming language), operators are special symbols that perform operations on variables and values. They are essential for performing mathematical, logical, and comparison operations in your programs.


πŸ”’ 1️⃣ Arithmetic Operators

Used to perform mathematical calculations.

OperatorDescriptionExampleOutput
+Addition5 + 38
-Subtraction10 - 46
*Multiplication6 * 318
/Division10 / 25.0
//Floor Division10 // 33
%Modulus (remainder)10 % 31
**Exponent2 ** 38

Example Program:

x = 10
y = 3print("Addition:", x + y)
print("Modulus:", x % y)
print("Exponent:", x ** y)

βš–οΈ 2️⃣ Comparison Operators

Used to compare values. The result is always True or False.

OperatorDescriptionExample
==Equal to5 == 5 β†’ True
!=Not equal5 != 3 β†’ True
>Greater than10 > 5 β†’ True
<Less than3 < 7 β†’ True
>=Greater or equal5 >= 5 β†’ True
<=Less or equal4 <= 7 β†’ True

πŸ”„ 3️⃣ Assignment Operators

Used to assign values to variables, often combined with arithmetic.

OperatorExampleMeaning
=x = 5Assign 5 to x
+=x += 3x = x + 3
-=x -= 2x = x – 2
*=x *= 4x = x * 4
/=x /= 2x = x / 2
%=x %= 3x = x % 3
**=x **= 2x = x ** 2
//=x //= 3x = x // 3

πŸ”— 4️⃣ Logical Operators

Used to combine conditions.

OperatorDescriptionExample
andTrue if both conditions are TrueTrue and False β†’ False
orTrue if any condition is TrueTrue or False β†’ True
notInverts the valuenot True β†’ False

🧩 5️⃣ Identity Operators

Used to check if two variables refer to the same object.

OperatorExampleOutput
isx is yTrue if same object
is notx is not yTrue if not same object

πŸ“¦ 6️⃣ Membership Operators

Check if a value exists in a sequence (like a list, tuple, or string).

OperatorExampleOutput
in'a' in 'apple'True
not in'b' not in 'apple'True

πŸ–¨ Example Program Using Multiple Operators

x = 10
y = 3# Arithmetic
print("Addition:", x + y)
print("Exponent:", x ** y)# Comparison
print("Is x greater than y?", x > y)# Logical
print("x > 5 and y < 5:", x > 5 and y < 5)# Membership
fruits = ["apple", "banana"]
print("Is 'apple' in fruits?", "apple" in fruits)

⭐ Key Points

  • Operators perform actions on variables or values.
  • Arithmetic β†’ numbers
  • Comparison β†’ True/False
  • Assignment β†’ store or update values
  • Logical β†’ combine conditions
  • Identity & Membership β†’ check object or sequence membership