Dear Ranjit,
It is not the interpreter alone in action and it flutters. From my learning by
going through the articles below.
It works in conjunction with Symbol table to determine the scope of each name
binding. So, before it reaches the print(x) in case 2. It has the symbol table
prepared for
On Saturday 02 July 2016 11:26 PM, ranjith pillay wrote:
But its kind of intriguing. In the 1st case the interpreter does not
find x in the local name space but finds it in the enclosing namespace.
The same argument should hold true for the 2nd case. I am not assigning
a new value to x but only p
on.org
> Subject: [Chennaipy] Python interpreter
> Message-ID:
> j5v4pk3iatdyjsusafhnpvu_...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hello friends,
>
> I have a question to ask.
>
> If you define the following cases:
>
> C
Dear Ranjit,
The interpreter is not confused. It actually points out the ambiguity in that
code/intention.An variable cannot be a global and local within that function's
scope. In this scenario you have to use theglobal keyword. Please check the
topic [Global vs. Local Variables and Namespaces |
Hello friends,
I have a question to ask.
If you define the following cases:
Case 1:
---
x = 1
def f():
print(x)
Case 2:
---
x = 1
def f():
print(x)
x = 5
print(x)
If you call the function f, in case 1 there won't be a problem, It will
print 1. But in case 2, it