Confused: appending to a list

Rene Pijlman reply.in.the.newsgroup at my.address.is.invalid
Thu Mar 23 11:46:34 EST 2006


DataSmash:
>I'm confused.  Why is it that when I say "while len(list) < 5:", I get
>5 items in my list.

Because the last time when len(list) was < 5, the block of code following
the while executed and did something to the list to give it a length >= 5
(otherwise the block of code would be executed again and it wouldn't have
been the last time).

>        list.append(num)

There you have it.

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl



More information about the Python-list mailing list