A global can be accessed by any function, but it can only be modified if you explicitly declare it with the 'global' keyword inside the function. Take, for example, a function that implements a counter. You could do it with global variables like this:
count = 0
def funct():
global count
count += 1
return count
print funct() # prints 1
a = funct() # a = 2
print funct() # prints 3
print a # prints 2
print count # prints 3
Now, this is all fine and good, but it is generally not a good idea to use global variables for anything except constants. You could have an alternate implementation using closures, which would avoid polluting the namespace and be much cleaner:
def initCounter():
count = 0
def incrementCounter():
count += 1
return count
#notice how you're returning the function with no parentheses
#so you return a function instead of a value
return incrementCounter
myFunct = initCounter()
print myFunct() # prints 1
a = myFunct() # a = 2
print myFunct() # prints 3
print a # prints 2
print count # raises an error!
# So you can use count for something else if needed!