Satori Komeiji's Programming Classroom
Oct 14, 2024 · Fundamentals
How Python’s VM Resolves Variable Lookups: LEGB, locals(), globals() and nonlocal
The article explains Python's variable lookup mechanism, detailing the LEGB rule, static storage of local variables, dynamic global namespace updates, common UnboundLocalError scenarios, bytecode inspection, and how the global and nonlocal keywords modify scope resolution.
LEGBglobalslocals
0 likes · 12 min read
