Skip to content

LEGB Principle – Variable Scopes

LEGB principle

Local Variables: variables defined inside of the function

Enclosed: Functions that are outside of this scope

Global: Module level, outside of any function

Built-in: Modules build in to python itself

global_variable = outside of any function

def outerfunction()

  enclosed_variable: outerfunction scope

  def innerfunction
  
    local_variable: Innerfunction scope
Published inPythonscripting