I have my code as below.
def test():
print num1
print num
num += 10
if __name__ == '__main__':
num = 0
num1 = 3
test()
When executing the above python code I get the following output.
3
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "<stdin>", line 2, in test
UnboundLocalError: local variable 'num' referenced before assignment
I do not know why particularly num is not available in test method. It is very weird for me and i did not face this yet before.
Note: I am using python 2.7.