Real Python·
Namespaces in Python
TL;DR
Reusing names in Python can make it confusing to know which variable your code will access. The tutorial explains how namespaces separate names and how Python looks them up in local, enclosing, global, then built-in scopes—the LEGB rule. Understanding these rules helps you avoid naming conflicts and unexpected variable-access errors.