Understanding the ‘LEGB’ Rule — In Python, there are four different variable scopes: Local, Enclosing, Global, Built-in. This leads to the ‘LEGB’ rule, which defines how Python resolves / looks up names. In this post we will introduce all scopes with examples, and also show how one can ‘interact’ between these — e.g. …