checking if two things do not equal None
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Mar 29 22:04:14 EDT 2014
On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote:
> I certainly agree that things like
>
>> if a is not b is not None: ...
>
> belong in an obfuscated coding contest.
Apart from the fact that I got it wrong (that's what happens when I post
at 6am after being up all night, thanks for the correction Lele), if you
consider chained comparisons to be "obfuscated", I think you're not
really fluent at Python. The OP even suggested `a != None != b` so I
think that (s)he at least understands chained comparisons.
However, I agree with Johannes that inverted conditions (using "not") are
sometimes harder to reason about than "regular" conditions.
--
Steven D'Aprano
http://import-that.dreamwidth.org/
More information about the Python-list
mailing list