TGViewer
Programming Resources | Python | Javascript | Artificial Intelligence Updates | Computer Science Courses | AI Books Programming Resources | Python | Javascript | Artificial Intelligence Updates | Computer Science Courses | AI Books @programming_guide · 56K subscribers
Post #3757 1.33K
✅ Python Conditional Statements if, elif, else! 🐍✨

Conditional statements allow your program to make decisions based on different conditions.

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


1. What is an if Statement?
Executes a block of code only if the condition is True.

age = 20
if age >= 18:
print("You are an adult")


✔ Output:
You are an adult

💡 If the condition is False, the code inside if is skipped.

2. if-else Statement:
Used when you want one action if the condition is True and another if it's False.

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


✔ Output:
Not eligible to vote

3. if-elif-else Statement:
Used to check multiple conditions.

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


✔ Output:
Grade B

4. Multiple Conditions with and:

age = 25
if age >= 18 and age <= 60:
print("Working age")


✔ Output:
Working age

5. Multiple Conditions with or:

day = "Saturday"
if day == "Saturday" or day == "Sunday":
print("Weekend")


✔ Output:
Weekend

6. Using not Operator:

is_logged_in = False
if not is_logged_in:
print("Please log in")


✔ Output:
Please log in

7. Nested if Statement:
An if statement inside another if.

age = 25
has_license = True
if age >= 18:
if has_license:
print("You can drive")


✔ Output:
You can drive

8. Short-Hand if Statement:

age = 20
if age >= 18: print("Adult")


✔ Output:
Adult

9. Ternary One-Line if-else:

age = 16
message = "Adult" if age >= 18 else "Minor"
print(message)


✔ Output:
Minor

💡 Useful for simple conditions in one line.

10. Practice Examples:

✔ Check even or odd

num = 8
if num % 2 == 0:
print("Even")
else:
print("Odd")


✔ Find the largest number

a = 10
b = 20
if a > b:
print(a)
else:
print(b)


✔ Check positive or negative

num = -5
if num >= 0:
print("Positive")
else:
print("Negative")


✔ Check password

password = "python123"
if password == "python123":
print("Access Granted")
else:
print("Access Denied")


💡 Conditional statements make your programs intelligent by allowing them to make decisions based on different situations.

💬 Tap ❤️ if this helped you learn Python!
  • ❤ 6
  • 👍 1
More from @programming_guide
  1. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
  2. Sep 29, 2026🧠 Core Programming Concepts You Should Know 💻🚀 These are the fundamental ideas behind a…
  3. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
  4. Sep 28, 2026YOU SHOULD WRITE CODE ON PAPER 📜IF U R BEGINNER ... HERE IS WHY 🤔 If you're a beginner l…
  5. Sep 28, 2026🎓 𝗛𝗔𝗥𝗩𝗔𝗥𝗗 𝗨𝗡𝗜𝗩𝗘𝗥𝗦𝗜𝗧𝗬 𝗙𝗥𝗘𝗘 𝗢𝗡𝗟𝗜𝗡𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 😍 Dreaming of…
  6. Sep 27, 2026Big Data Roadmap | |-- Fundamentals | |-- Introduction to Big Data | | |-- Characteristics…
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 →