[Tutor] Another assert() question

Alan Gauld alan.gauld at btinternet.com
Sun Jul 13 09:50:17 CEST 2008

"Dick Moores" <rdm at rcblue.com> wrote 

> But why will a tuple with two elements will always evaluate to
> True?

Thats the rule for evaluationg collections in Python.
An empty collection is False. Anything else is therefore true

if []: -> false

if [1,2]: -> true

if (): -> false

if (1,2) - True

if "": -> False

if "foo": -> True

Does that help?

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list