On 5/14/2011 3:39 AM, Steven D'Aprano wrote:

Th money-quote as regards using arbitrary objects in truth tests:

     [quote]
     All this changed with the introduction of the two-element
     boolean domain {true, false} which provides the vocabulary
     needed to assign values to boolean expressions: 3<4 is a
     way for writing true, 3>4 is a way for writing false,
     whereas the value of x>0 depends on the value of x ...
     [end quote]


In Python, [1, 2, 3] is another way of writing true, and [] is another
way of writing false. Similarly with any other arbitrary objects.

Another way to look at it is that Python automatically calls bool() on every expression in its two boolean or conditional contexts: 'if e:' and 'while e'. This is a boilerplate-removing, labor-saving convenience. Python has many such conveniences.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to