Functions access to global variables

You can list several variables using the same global statement.

An example:

x = 34
y = 32

def f():
    global x,y
    x = 1
    y = 2

This way your list of global variables used within your function will can be contained in few lines.

Nevertheless, as @BrenBarn has stated in the comments above, if your function does little more than initializating variables, there is no need to use a function.


Take a look at this.

Using a global variable inside a function is just as easy as adding global to the variable you want to use.