Python Closures

Python closures are functions bundled up with variables they access in outer, non-local scopes of enclosing functions. Closures are essential when inner functions need access to variables from their enclosing scope because without them, these variables would be lost once the enclosing function completes execution.
Read MorePython Closures

The Python nonlocal Keyword

The Python nonlocal keyword is used to access and modify variables from an outer (but not global) scope in nested functions (i.e. non-local variables). It tells Python that a variable assigned in a nested function should refer to a variable in the nearest enclosing scope that is not global. Otherwise, Python will create a new variable in the local scope of the nested function.
Read MoreThe Python nonlocal Keyword

The Python __name__ Variable

The Python __name__ variable is a special built-in variable that holds the name of the current imported module. When accessed within a Python script file that's executed directly (i.e. not a module), its value is the string "__main__". __name__ is most often used to differentiate between Python code that is run in a standalone script or code that's imported as a module.
Read MoreThe Python __name__ Variable