Q:

Scope of Python variables in this case - Difference between Enclosing and Local Variable

I am confused about the scope of python variables. How is this working
Consider the following example
i = 12
if i==12 :
    str = "is equal"
else:
    str = "NOT"
print str  //Prints is equal - recognized the string str

The variable str is only in the scope of if statement and its scope is lost at the else statement. Since there is no hoisting in python. I am confused how this example works.I read this post and it states that Variables are scoped in the Following order

1-L (local variables are given preference)
2-E (Enclosing variables)
3-G (Global variables)
4-B (Builtin)

My question is what is the difference between Enclosing variable and local variable ?

A:

The variable str is only in the scope of if statement and its scope is lost at the else statement.

Nope. Python is function scoped, not block scoped. Entering an if block doesn't create a new scope, so the str variable is still in scope for the print.
Enclosing variables are variables from functions enclosing a given function. They occur when you have closures:
def f():
    x = 3
    def g():
        print x  # enclosing variable
    g()

