How Python decides what a name means — the LEGB lookup rule, what a closure actually captures, the late-binding loop trap and its fixes, and when you genuinely need `nonlocal` or `global`.
How Python decides what a name means — the LEGB lookup rule, what a closure actually captures, the late-binding loop trap and its fixes, and when you genuinely need `nonlocal` or `global`.
Module 2 introduced closures as anonymous functions that capture their environment. But once you start passing functions around as values — storing callbacks, building higher-order APIs, returning behavior from functions — a few subtleties surface: functions and closures aren't quite the same type, returning a closure requires a boxing trick, and the `Fn` trait family has a precise structure worth knowing. These details show up constantly in real Rust APIs, and mastering them makes you fluent in Rust's functional side.
Module 2 introduced closures. But once you start passing functions around as values — callbacks, higher-order APIs, returning behavior — subtleties surface: functions and closures aren't quite the same type, returning a closure requires a boxing trick, and the Fn trait family has a precise structure worth knowing.