condition and True or False

David Robinow drobinow at gmail.com
Sun May 2 16:16:21 EDT 2010


On Sun, May 2, 2010 at 1:14 PM, Paul McGuire <ptmcg at austin.rr.com> wrote:
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
True and False were added in Python 2.2.1  (PEP 285)
Perhaps this was a silly way to ensure that the user wouldn't try to
run it in earlier versions.



More information about the Python-list mailing list