if and True
Lines 1 and 2 store two values: age is 8 and member is False. The program uses them to choose a ticket price. The track on the right shows every path it could take.
Line 3 compares. Python reads age and asks: is 8 less than 13? A comparison always answers with a bool, True or False. Here: True. The six comparisons are ==, !=, <, >, <= and >=.
if runs its block only when its condition is True. It is, so the token takes the top path and line 4 runs: price = 5 lands in memory.
How does Python know line 4 belongs to the if? The colon on line 3 opens a block, and the lines under it, pushed in by four spaces, are that block. Lines 6 and 8 are blocks too.
Once one block has run, Python skips the remaining elif and else and carries on at line 9. print(price) shows 5. Only one path is ever taken.
elif and else
Run it again with age = 30. Is 30 less than 13? No: False. When the condition is False, Python skips the if block, so line 4 does not run. The token turns down the track instead.
elif means "else if": a second question, asked only because the first answer was False. Is age >= 65? False. Is member True? No. Neither side is True, so the test is False and line 6 is skipped.
else has no question. Its block runs when every test above it was False. So line 8 runs and price = 10 lands in memory; then line 9 prints 10.
and, or, not
Now member = True. age < 13 is False again, so Python moves on to elif. or is True when one side is True: age >= 65 is False but member is True, so the test is True. and needs both; not flips it.
The elif test is True, so its block runs: price = 6. The else block is skipped, and line 9 prints 6. Same code, three inputs, three different paths.
Try it in Python
;; step 1/10 · run 1: age = 8, member = False >>> age = 8 >>> member = False >>> type(member) <class 'bool'>
Python checks the tests from the top, runs the block of the first one that is True, and skips every other block of that if statement; tests below the True one are not even evaluated. An if accepts any value, not only True and False. 0, 0.0, an empty string "" and None count as false; most other values count as true.