# Bruce Maxwell # Fall 2010 # # Example of scoping Python # topA = 1 midA = 2 botA = 3 print 'topA at top level: ', topA print 'midA at top level: ', midA print 'botA at top level: ', botA def top( topA ): # all three are local variables in this function midA = 12 botA = 13 print 'topA in function top: ', topA print 'midA in function top: ', midA print 'botA in function top: ', botA def middle( midA ): # topA comes from the top function # midA and botA are local variables botA = 23 print 'topA in function middle: ', topA print 'midA in function middle: ', midA print 'botA in function middle: ', botA def bottom( botA ): # topA comes from the top function # midA comes from the middle function # botA is a local variable print 'topA in function bottom: ', topA print 'midA in function bottom: ', midA print 'botA in function bottom: ', botA bottom( 33 ) middle( 11 ) print 'topA in function top: ', topA print 'midA in function top: ', midA print 'botA in function top: ', botA top( 0 ) # nothing changed at the global level print 'topA at top level: ', topA print 'midA at top level: ', midA print 'botA at top level: ', botA