Python · Lesson 4 of 9
Conditions
if, elif, else, comparison operators and and / or / not.
Conditions let your program choose. Python checks each test from the top and runs the first block whose condition is true.
if score >= 75:
print("Shortlisted")
elif score >= 50:
print("Waitlisted")
else:
print("Not selected")
Note the colon : at the end of each test and the indented block underneath.
Comparisons: == != < > <= >=. Combine with and, or, not. Check membership with in: "sql" in skills.
Try it yourself
Press Run to see the output.
Edit and press Run (or Ctrl/⌘ + Enter). Python runs in your browser — the first run downloads the Python engine and takes a few seconds.
Key points
- Each test ends with a colon.
- elif = else if; only the first true branch runs.
- in checks membership in lists and strings.
Quick check
Which keyword checks another condition after if?
Python uses elif for additional conditions.
Practice task
Write a program that takes a marks variable and prints Distinction (≥ 80), First class (≥ 60), Pass (≥ 40) or Fail.
Interview corner
What values are 'falsy' in Python?
False, None, 0, 0.0, empty string '', and empty containers such as [], {}, set() and (). Everything else is truthy.
What is the difference between == and is?
== compares values; is checks whether two names point to the same object. Use is mainly for None checks: if x is None.
Further reading
Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.
Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.