bhylu.com

Advertisements

Shorthand If

A short conditional expression can assign one of two values clearly. Keep it simple enough that the condition is visible at a glance.

Understand the idea

The expression evaluates only the selected branch. A full if statement remains the better choice when either branch has multiple operations or requires explanation. Shorthand is a readability option, not a goal of reducing every decision to one line.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

A worked example

Python

is_member = True
fee_cents = 800 if is_member else 1000
print(fee_cents)

Read the result

The output is 800 because the member branch is selected.

Try one change

Rewrite the fee choice with if and else, then add a separate concession rule without nesting expressions.