Now, if a function contains an assignment to the variable, the variable is considered to be local to the function and hides the global variable with the same name.
Because (the local) num is not assigned a value at the time of the print() function, an UnboundLocalError exception (with the explanation local variable 'num' referenced before assignment) is thrown:
num = 42
def printNumAndIncrement(i):
print(num)
num = num + i
printNumAndIncrement(57)
printNumAndIncrement( 1)