why is the scope different for int
and list
in Python? Below is my example
#!/usr/bin/python
class Foo:
def method(self):
l = []
i = 0
def method1():
l.append(1)
i = i + 1 <<<<<< Throws exception
method1()
Foo().method()
In the above example, I can access the list l
inside my method1
function but not the integer i
. Any possible explanation?
I referred to the below link, but it had no explanation about the above scenario.