[openstack-dev] "if X not in Y" vs. "if not X in Y" consensus?

Dean Troyer dtroyer at gmail.com
Thu Jan 31 15:35:57 UTC 2013


On Thu, Jan 31, 2013 at 8:52 AM, Dolph Mathews <dolph.mathews at gmail.com> wrote:
> +1 for "X not in Y"
>
> "not X in Y" reads ambiguously to me.

And there's the reason it matters...it actually is not ambiguous
according to operator precedence rules
(http://docs.python.org/2/reference/expressions.html#not-in):

in "X not in Y" 'not' is part of the membership operator

in "not X in Y" 'not' is a boolean operator on X, returning True or False

These really are different operations that may have the same result
for some data types and values.  Phew!  There is still only one way to
do it right...

dt

-- 

Dean Troyer
dtroyer at gmail.com



More information about the OpenStack-dev mailing list