Alain Ketterlin alain at
Thu Oct 23 16:47:27 CEST 2014

Simon Kennedy <sffjunkie at> writes:

> Just out of academic interest, is there somewhere in the Python docs where the following is explained?
>>>> 3 == True
> False
>>>> if 3:
> 	print("It's Twue")
> It's Twue
> i.e. in the if statement 3 is True but not in the first

says: "The if statement [...] selects exactly one of the suites by
evaluating the expressions one by one until one is found to be true (see
section Boolean operations for the definition of true and false)"

and then:

says: "In the context of Boolean operations, and also when expressions
are used by control flow statements, the following values are
interpreted as false: False, None, numeric zero of all types, and empty
strings and containers (including strings, tuples, lists, dictionaries,
sets and frozensets). All other values are interpreted as true."

(links are to the 2.7 version of the reference manual, I think not much
has changed in 3.* versions.)

-- Alain.

More information about the Python-list mailing list