TGViewer
Data Science & Machine Learning Data Science & Machine Learning @datasciencefun · 77.8K subscribers
Post #4072 4.07K
✅ Conditional Statements (if–else) 🐍⚡

Conditional statements allow programs to make decisions based on conditions.

👉 Used heavily in:
✔ Data filtering
✔ Business rules
✔ Machine learning logic

🔹 1. if Statement
Used to execute code when a condition is True.

✅ Syntax
if condition:
# code


Example
age = 20
if age >= 18:
print("You can vote")

# Output: You can vote

🔹 2. if–else Statement
Used when there are two possible outcomes.

Syntax
if condition:
# code if true
else:
# code if false


Example
age = 16
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible")


🔹 3. if–elif–else Statement
Used when there are multiple conditions.

Syntax
if condition1:
# code
elif condition2:
# code
else:
# code


Example
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 60:
print("Grade B")
else:
print("Grade C")


🔹 4. Nested if Statement
An if statement inside another if.

age = 20
citizen = True
if age >= 18:
if citizen:
print("Eligible to vote")


🔹 5. Short if (Ternary Operator)
age = 20
print("Adult") if age >= 18 else print("Minor")


🎯 Today’s Goal
✔ Understand if
✔ Use if–else
✔ Use elif for multiple conditions
✔ Learn nested conditions

👉 Conditional logic is used in data filtering and decision models.

Double Tap ♥️ For More
  • ❤ 16
  • 👏 1
More from @datasciencefun
  1. Oct 15, 2026Post #4665
  2. Oct 15, 2026Post #4664
  3. Oct 15, 2026Post #4663
  4. Oct 15, 2026Post #4662
  5. Oct 13, 2026𝗧𝗢𝗣 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 𝗧𝗢 𝗕𝗢𝗢𝗦𝗧 𝗬𝗢𝗨𝗥 𝗦𝗞𝗜𝗟𝗟𝗦 𝗜𝗡 𝟮𝟬𝟮𝟲! Explor…
  6. Oct 12, 2026Used when you want to perform calculations for each department. Simple rule: DISTINCT → Gi…
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 →