# example of not looking in the middle scope a = 5 def func(): b = 6 def nested1(): print ' a has value: ', a print ' b has value: ', b def nested2(): a = 55 b = 66 print ' a has value: ', a print ' b has value: ', b def nested3(): try: print ' a has value: ', a except: print ' a is undefined' try: print ' b has value: ', b except: print ' b is undefined' a = 555 b = 666 print ' a has value: ', a print ' b has value: ', b def nested4(): global a global b print ' a has value: ', a try: print ' b has value: ', b except: print ' b is undefined' nested1() nested2() nested3() nested4() func()