Question about 'print' in a loop
fl
rxjwg98 at gmail.com
Wed Nov 18 22:20:09 EST 2015
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 code should.
>
> Before you ask for comprehension of "this phenomenon", why don't you
> tell us what you expect your code to do, and why? I just asked my
> non-programmer sister and she was completely unsurprised by what
> Python did here.
>
> ChrisA
Excuse me. That is my unclear question.
I expect that each call sq will have one print 'here', as I suppose that
print 'here' is inside the loop.
Oh, I just realize that it is not a function. It constructs list sq.
When the loop (function as a constructor (not necessarily correct called),
it print 5 'here'.
Thanks for you feedback.
More information about the Python-list
mailing list