Conditional expression (a if c else b)
A conditional expression picks one of two values based on a condition, all in one line.
Used in 100 lessons of the course, from 00.01.
You read it left to right like a sentence: a if c else b means "a, if c holds; otherwise b".
Python evaluates the condition c first. If it is true, the result is a. If not, it is b. Only the chosen branch is evaluated.
The difference from a regular if is that this is an expression: it produces a value. So you can assign it to a name, pass it to a function, or put it inside an f-string.
The course uses it like this: hint = f" Did you mean: {', '.join(suggestions)}?" if suggestions else " Try search() instead.". If the suggestions list has items, it is truthy and hint gets the first text. If it is empty, it gets the second.
Use it for short choices. If you need several lines or several actions, a regular if reads better.
Reach for it when: you need to pick one of two values to assign or use right away, and the choice fits on one line.
Examples
Common mistake
n = 5 result = "big" if n > 3 print(result)
Why: A conditional expression always needs the `else`: Python must know which value to give when the condition is false.
How to write it: Add the other branch: "big" if n > 3 else "small".
