The scope of a variable determines the visited scope of a variable. Since no variable declaration is needed in Python, the scope of a variable is where it appears. We usually do not pay much attention to the scope of a variable, but it often causes great trouble to us if there is any problem. So we can not ignore it. As for a global variable or local variable, we may consider it like this, a variable in a function is a local variable, while that in the body of program code is a global variable. Let's look at a program, global_str is inside the body of program code. Therefore, it is a global variable. By contrast, local_str is located in the function foo(). Thus, it is a local variable. During the execution of function, local_str is visible within the function. Sure, a global variable is also visible, so the result of execution is "helloworld". If there is such a case, when a global variable and a local variable share the same name, what will happen? Like in this instance, if we call the function f(), will the result be 9 or 25? It is 25. The reason is, if a global variable and a local variable share the same name, such a principle is observed -- the inner one will mask the outer one. Think about another question. If we want to modify the value of a global variable, can we do that in a function? Let's look at this example. There is a global variable "a", whose original value equals 3. Sure, we may output its value inside the function. Can this statement be properly executed? It is possible to re-assign the global variable "a" in some programming languages, but an error occurs in Python, as we see. The error says, the local variable "a" referenced before assignment. To assign a variable defined outside the function, what shall we do? This method seems obviously impossible. In Python, you need to tell it, this variable is not local, but global. This requires the global statement. Let's make a change to the program just now. With "global a" plus this statement, conduct assignment again. The original value of a is 3, not changed to 5. Let's see the program execution. With f(8), the actual argument "8" is transferred to the formal argument "x". "a" is a global variable emphasized with the global statement. We output the value of "a", i.e. 3 and re-assign 5 to a. For its attribute, this statement can be properly executed. Print the value of a+x, i.e. "5+8" So, the second value is 13. f(8) is completely executed. The last statement is "print(a)". We may think about it, is it 3 or 5 that is printed at last? Since "a" is a global variable emphasized by the global statement, its value has been changed, so the result is 5. The final output results are 3, 13 and 5. In programming, we often require strong cohesion in modules, and weak coupling with other modules. Obviously, a global variable does not conform to this principle. Certainly, we do not mean we should totally abandon global variables. If the use of a global variable can significantly improve the performance of a program or make designing much easier, we may appropriately use some global variables.