On Sun, May 12, 2019 at 8:05 AM Arup Rakshit wrote:
>
> In the following the function, x is reachable outside the scope of foo
> function.
>
> In [1]: x = 10
>
> In [2]: def foo():
>...: return x
>...:
>
> In [3]: print(foo())
> 10
To what the others have said I wish to point out tha
Hello Arup,
> In the following the function, x is reachable outside the scope of foo
> function.
> In [1]: x = 10
> In [2]: def foo():
>...: return x
> In [3]: print(foo())
> 10
> But why it is not the case when the look up happens inside a
> instance method of a class?
>
> In [1]: c
On 12/05/2019 14:04, Arup Rakshit wrote:
The first case x is a global variable - which in
Python really means module level.
In the second case you have placed it inside
Foo so you need to specify that that is where
it is located. Classes encapsulate their own
methods and attributes, that is one o