Variable Scoping

By default, variables that are assigned to in a function only exist within that function - i.e. they have local scope.

The global statement declares that a variable has global scope.
This will make it visible outside of the function, after the function has been called.
It also allows you to use variables already defined in the global scope.

>>> def foo(a):
...     global y
...     y = a
...     print y
...
>>> foo(12)
12
>>> print y
12