fl writes:
> Hi,
>
> From previous post, I get many helpful replies. Now I have a new question
> when I run this example code:
>
>
> -
> sq=[]
> for xx in range(5):
> print 'here'
> sq.append(lambda:xx**2)
> ...
> sq[2]()
> Out[151]: 16
>
> sq[3]()
> Out[152]: 16
> /
Same rea
On Wednesday, November 18, 2015 at 10:11:24 PM UTC-5, Chris Angelico wrote:
> On Thu, Nov 19, 2015 at 1:55 PM, fl wrote:
> > There are only one time 5 'here' printed out, but there is no 'here' print
> > out in thereafter call sq[2]() etc. How to understand this phenomenon?
>
> Code does what cod
On Thu, Nov 19, 2015 at 1:55 PM, fl wrote:
> There are only one time 5 'here' printed out, but there is no 'here' print
> out in thereafter call sq[2]() etc. How to understand this phenomenon?
Code does what code should.
Before you ask for comprehension of "this phenomenon", why don't you
tell u
Hi,
>From previous post, I get many helpful replies. Now I have a new question
when I run this example code:
-
sq=[]
for xx in range(5):
print 'here'
sq.append(lambda:xx**2)
here
here
here
here
here
xx
Out[150]: 4
sq[2]()
Out[151]: 16
sq[3]()
Out[152]: 16
/
There are