condition and True or False

Paul McGuire ptmcg at austin.rr.com
Sun May 2 13:14:44 EDT 2010


While sifting through some code looking for old "x and y or z" code
that might better be coded using "y if x else z", I came across this
puzzler:

    x = <boolean expression> and True or False

What is "and True or False" adding to this picture?  The boolean
expression part is already evaluating to a boolean, so I don't
understand why a code author would feel compelled to beat this one
over the head with the additional "and True or False".

I did a little code Googling and found a few other Python instances of
this, but also many Lua instances.  I'm not that familiar with Lua, is
this a practice that one who uses Lua frequently might carry over to
Python, not realizing that the added "and True or False" is redundant?

Other theories?

-- Paul



More information about the Python-list mailing list