Message from discussion which a is used?
Received: by 10.66.85.225 with SMTP id k1mr1992458paz.32.1348531725531;
Mon, 24 Sep 2012 17:08:45 -0700 (PDT)
Received: by 10.68.212.99 with SMTP id nj3mr1480191pbc.20.1348531725468; Mon,
24 Sep 2012 17:08:45 -0700 (PDT)
Date: Mon, 24 Sep 2012 17:08:45 -0700 (PDT)
Injection-Info: wm7g2000pbc.googlegroups.com; posting-host=220.127.116.11; posting-account=rYyWJQoAAACVJO77HvcyJfa3TnGYCqK_
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4
(KHTML, like Gecko) Chrome/22.0.1229.56 Safari/537.4,gzip(gfe)
Subject: Re: which a is used?
From: alex23 <wuwe...@gmail.com>
Injection-Date: Tue, 25 Sep 2012 00:08:45 +0000
Content-Type: text/plain; charset=ISO-8859-1
On Sep 25, 9:43=A0am, Jayden <jayden.s...@gmail.com> wrote:
> Dear All,
> I have a simple code as follows:
> # Begin
> a =3D 1
> def f():
> =A0 =A0 print a
> def g():
> =A0 =A0 a =3D 20
> =A0 =A0 f()
> I think the results should be 20, but it is 1. Would you please tell me w=
Because you don't declare 'a' in 'f', it looks for 'a' in the
surrounding scope _where it was defined_, not where it was called.
Because 'a' in the module scope is 1, you'll get 1.