thing although there are times when globals are usefulvariables assigned in def are local by default because that is normally the best policy changing globals can lead to well-known software engineering problemsbecause the variablesvalues are dependent on the order of calls to arbitrarily distant functionsprograms can become difficult to debugor to understand at all consider this module filefor examplewhich is presumably imported and used elsewherex def func ()global def func ()global nowimagine that it is your job to modify or reuse this code what will the value of be herereallythat question has no meaning unless it' qualified with point of reference in time--the value of is timing-dependentas it depends on which function was called last (something we can' tell from this file alonethe net effect is that to understand this codeyou have to trace the flow of control through the entire program andif you need to reuse or modify the codeyou have to keep the entire program in your head all at once in this caseyou can' really use one of these functions without bringing along the other they are dependent on--that iscoupled with--the global variable this is the problem with globalsthey generally make code more difficult to understand and reuse than code consisting of self-contained functions that rely on locals on the other handshort of using tools like nested scope closures or object-oriented programming with classesglobal variables are probably the most straightforward way in python to retain shared state information--information that function needs to remember for use the next time it is called local variables disappear when the function returnsbut globals do not as we'll see laterother techniques can achieve thistooand allow for multiple copies of the retained informationbut they are generally more complex than pushing values out to the global scope for retention in simple use cases where this applies moreoversome programs designate single module to collect globalsas long as this is expectedit is not as harmful programs that use multithreading to do parallel processing in python also commonly depend on global variables--they become shared memory between functions running in parallel threadsand so act as communication device for nowthoughespecially if you are relatively new to programmingavoid the temptation to use globals whenever you can--they tend to make programs difficult to un scopes