Unless I’m crazy if None not in x and if not None in x are equivalent. Is there a preferred version? I guess None not in is more english-y and therefore more pythonic, but not None in is more like other language syntax. Is there a preferred version?
Unless I’m crazy if None not in x and if not None in x
Share
They compile to the same bytecode, so yes they are equivalent.
The documentation also makes it clear that the two are equivalent:
As you mention
None not in xis more natural English so I prefer to use this.If you write
not y in xit might be unclear whether you meantnot (y in x)or(not y) in x. There is no ambiguity if you usenot in.