Line 1 tells the computer to create a variable. As this variable is not inside a function and as such we call it a global variable. Effectively this variable is available in all functions. The function z(), lines 20 to 22, show the variable A being printed. However the variable A is not defined in z(). Because A is a global variable, or more correctly has global scope, it will be made available to all functions. When we look at environments we will see why this is the case.

Any changes to A made in functions will change the value of A. Line 8, A=50, is inside the function y(). This has now changed the value of A for all other functions. This means that any assignment to A from within y() will effect all other functions which make use of this globally scoped variable. This is a very important point to consider.

Global variables are very much a double edged sword. They are great for storing data between function calls. However it is important that the access to the variable is controlled carefully. If it is changed with no control then its value can not be relied upon. As such programming standards tends to move people away from using globally scoped variables. In fact it is possible to do away with them completely. This idea can be explored for homework.