B14 - variable scopes and lookup

variable scope rules

b = 6

def f1(a):
    print(a)
    print(b)
    b = 9
    
f1(1)

variable lookup logic

x = 10

def func():
	print(x)
	
func() ## 10
x = 10

def func():
	x = 5
	print(x)
  
func()    ## 5
print(x) ## 10
x = 10

def func(x):
	print(x)
  
func(15)    ## 15
def outer():
    a = 10 

    def inner():
        print(a)  ## a is not assigned in inner, so python looks up in outer
    inner()

outer() ## 10