Conditional expressions

For a choice between two values, Python has an expression form: value_if_true if condition else value_if_false. Other languages write this as cond ? a : b.

The order reads like English, which trips people up at first: the condition sits in the middle. Only the chosen side is evaluated, so x / y if y else 0 never divides by zero.

Use it for short, simple choices, like a label or a default. If you find yourself nesting them, write a normal if instead. Readable code scores better in an interview than clever code.

Run it, then change n to a negative number.