Real Python

Get Your Code: Click here to download runnable LEGB examples that show how Python looks up a name in local, enclosing, global, and built-in scopes.

Almost there! Complete this form and click the button below to gain instant access:

Namespaces and Scopes in Python

Trace Python's LEGB Scope Rule Step by Step

๐Ÿ”’ No spam. We take your privacy seriously.

ยฉ 2012โ€“2026 Real Python โ‹… Privacy Policy