amazing scope?
Chris Angelico
rosuav at gmail.com
Fri Nov 30 11:08:45 EST 2012
On Sat, Dec 1, 2012 at 3:05 AM, andrea crotti <andrea.crotti.0 at gmail.com> wrote:
> Well I knew that this works fine, even if I feel a bit guilty to do
> this, and better is:
>
> foo = 'bar' if some_condition else 'baz'
>
> Anyway for me the suprise is that something that is defined *later* at
> the module scope is found in a function which is defined *earlier*.
It's assigned to earlier. It's no different from C code like this:
int foo;
void blah()
{
/* do stuff with foo */
}
int main()
{
foo = 1;
}
In Python, the "int foo;" is implicit, but the scope is the same.
ChrisA
More information about the Python-list
mailing list