Python Flow Ride — Python

Becak route: 20 levels tracing Python: for/else, the mutable default trap, late-binding closures, is vs == and the iterator protocol, on a mini CPython.

What the levels ask

  1. The bus has just left the depot. Predict the output and the final value of hasil.
  2. The bus picks which road to take. Only ONE branch runs.
  3. Predict the numbers printed by the loop.
  4. In Python, a loop has an else clause. Predict whether the else runs.
  5. Now with a break. Does the else run?
  6. Predict the final contents of the list a.
  7. A swap trick with no helper variable. Predict the final values.
  8. Python 3.7+ guarantees insertion order. Predict the output.
  9. An f-string + a format spec for a decimal number.
  10. The two "look alike", but they behave differently. Predict the output.
  11. The loop order in a nested comprehension often trips people up.
  12. A classic Python bug. Predict the output: it might not be what you'd expect.

And more, 20 levels in all.