Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Closure:** Function capturing enclosing scope. `def make_adder(n): return lambda x: x+n`. Inner 'closes over' n. **Use:** Callbacks, decorators, factories. **Gotcha:** Late binding in loops—`lambda x: x*i` captures i by reference; use `lambda x, i=i: x*i`. **Why:** DI,...
Pro-Move: Default arg fix for loop closures. Red Flag: Unaware of late-binding gotcha.
Closure: Function capturing enclosing scope. def make_adder(n): return lambda x: x+n. Inner 'closes over' n. Use: Callbacks, decorators, factories. Gotcha: Late binding in loops—lambda x: xi captures i by reference; use lambda x, i=i: xi. Why: DI, config. Production: Default arg for early binding.
Pro-Move: Default arg fix for loop closures. Red Flag: Unaware of late-binding gotcha.
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.