var = "Old world"
class a(object):
def b(self):
print(var)
#var = "Updated world"
aObj = a()
aObj.b()
When I run the above code it works fine.
But when i uncomment line 5 var="Updated World"
it throws UnboundLocalError on line 4.
I understand that i cannot modify var at line 5. But why I'm getting an error at line 4. Any good inputs are welcome.