Modifying global variables in Python

You need to declare a global variable with global before you can modify it. Otherwise, you will just be creating a local variable with the same name.

x = 0

def main():
    f1(1)
    print x # prints 0
    f2(2)
    print x # prints 2

def f1(number):
    x = number

def f2(number):
    global x
    x = number

if __name__ == '__main__':
    main()