TGViewer
Artificial Intelligence Artificial Intelligence @machinelearning_deeplearning · 56.3K subscribers
Post #1861 1.8K
In the previous post, we learned how to convert one data type into another using Type Casting. Now, let's explore Operators, which allow us to perform calculations, compare values, and make decisions in our programs.

📖 Phase 1: Programming Fundamentals

📌 Topic 8: Operators

Operators are special symbols or keywords used to perform operations on variables and values.
Think of operators as tools that help you calculate, compare, assign values, or combine conditions in a program.

Why Do We Need Operators?
Operators help us:
• Perform mathematical calculations
• Compare values
• Assign values to variables
• Combine multiple conditions
• Make decisions in programs

1. Arithmetic Operators
Used for mathematical calculations.

Operators:
• + Addition: 10 + 5 = 15
• - Subtraction: 10 - 5 = 5
• * Multiplication: 10 * 5 = 50
• / Division: 10 / 5 = 2.0
• // Floor Division: 10 // 3 = 3
• % Modulus (Remainder): 10 % 3 = 1
• ** Exponent: 2 ** 3 = 8

Example:

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


2. Comparison Operators
Compare two values and always return True or False.

Operators:
• == Equal to
• != Not equal to
• > Greater than
• < Less than
• >= Greater than or equal to
• <= Less than or equal to

Example:

x = 10
y = 20

print(x == y) # False
print(x != y) # True
print(x < y) # True
print(x >= y) # False


3. Assignment Operators
Used to assign or update values.

x = 10

x += 5 # 15
print(x)

x *= 2 # 30
print(x)

x -= 4 # 26
print(x)


4. Logical Operators
Combine multiple conditions.

Operators:
• and Returns True if both conditions are true
• or Returns True if at least one condition is true
• not Reverses the result

Example:

age = 25

print(age > 18 and age < 60) # True
print(age < 18 or age > 60) # False
print(not(age > 18)) # False


5. Membership Operators
Check whether a value exists in a sequence.

Operators:
• in Value exists
• not in Value does not exist

Example:

fruits = ["Apple", "Banana", "Mango"]

print("Apple" in fruits) # True
print("Orange" not in fruits) # True


6. Identity Operators
Check whether two variables refer to the same object in memory.

Operators:
• is Same object
• is not Different objects

Example:

a = [1, 2]
b = a
c = [1, 2]

print(a is b) # True
print(a is c) # False


Common Beginner Mistakes
❌ Using = instead of == while comparing values
❌ Confusing / with //
❌ Forgetting that and requires both conditions to be True

Best Practices
✅ Use meaningful variable names
✅ Choose the correct operator for the task
✅ Use parentheses to make complex conditions easier to read

Key Takeaways
• Operators perform calculations, comparisons, and logical operations
• Arithmetic operators are used for math
• Comparison operators return True or False
• Assignment operators simplify updating variables
• Logical operators combine multiple conditions
• Membership and Identity operators help work with collections and objects

➡️ Double Tap ❤️ For More
  • ❤ 7
More from @machinelearning_deeplearning
  1. Sep 22, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous posts, we learned about fun…
  2. Sep 21, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous post, we explored functions…
  3. Sep 20, 2026In the previous post, we learned how conditional statements allow Python programs to make…
  4. Sep 19, 2026In the previous post, we explored Python operators and even tested ourselves with some tri…
  5. Sep 17, 2026In the previous post, we learned how to take input from users and display output. One impo…
  6. Sep 16, 2026🚀 GigaChat 3.5 Reasoning — a new open-source LLM that thinks before it answers. It breaks…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →