Confused: appending to a list

Rene Pijlman at
Thu Mar 23 17:46:34 CET 2006

>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?

More information about the Python-list mailing list