[Tutor] Testing for empty list

Luke Paireepinart rabidpoobear at gmail.com
Mon Oct 19 09:38:55 CEST 2009

On Mon, Oct 19, 2009 at 2:26 AM, Todd Matsumoto <tmatsumoto at gmx.net> wrote:

> The while loop will print each index of the list.

No it's printing each element of the list, not the index.

> In a way it checks that if the list is empty by printing the items. As far
> as I know there isn't any 'True' or 'False' output from a list.

I'm not sure what you mean here because...

> If you want to do something if mylist is empty you can check it like this:
> if not mylist:

An "if" statement checks a boolean state so the list must be evaluating to a
boolean somehow.  (It does, it's False if it's empty and True otherwise).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091019/312c1b8e/attachment-0001.htm>

More information about the Tutor mailing list