def fib( )"""assumes an int > returns fibonacci of ""global numfibcalls numfibcalls + if = or = return elsereturn fib( - fib( - def testfib( )for in range( + )global numfibcalls numfibcalls print 'fib of' '='fib(iprint 'fib called'numfibcalls'times figure using global variable in each functionthe line of code global numfibcalls tells python that the name numcalls should be defined at the outermost scope of the module (see section in which the line of code appears rather than within the scope of the function in which the line of code appears--despite the fact that numfibcalls occurs on the left-hand side of an assignment statement in both fib and testfib (had we not included the code global numfibcallsthe name numfibcalls would have been local to each of fib and testfib the functions fib and testfib both have unfettered access to the object referenced by the variable numfibcalls the function testfib binds numfibcalls to each time it calls fiband fib increments the value of numfibcalls each time fib is entered it is with some trepidation that we introduce the topic of global variables since the card-carrying computer scientists have inveighed against them the indiscriminate use of global variables can lead to lots of problems the key to making programs readable is locality one reads program piece at timeand the less context needed to understand each piecethe better since global variables can be modified or read in wide variety of placesthe sloppy use of them can destroy locality neverthelessthere are times when they are just what is needed modules so farwe have operated under the assumption that our entire program is stored in one file this is perfectly reasonable as long as programs are small as programs get largerhoweverit is typically more convenient to store different parts of them in different files imaginefor examplethat multiple people are working on the same program it would be nightmare if they were all trying to update the same file python modules allow us to easily construct program from code in multiple files module is py file containing python definitions and statements we could createfor examplea file circle py containing