Checking whether type is None
steve+comp.lang.python at pearwood.info
Thu Jul 26 01:53:12 EDT 2018
On Wed, 25 Jul 2018 16:14:18 +0000, Schachner, Joseph wrote:
> While I appreciate that use of "is" in thing is None, I claim this
> relies on knowledge of how Python works internally, to know that every
> None actually is the same ID (the same object) - it is singular.
No, it isn't knowledge of Python's internal working. None is a singleton
object is a language guarantee, a promise that will always be true in any
It is no more about "how Python works internally" than knowing that the
keyword is spelled "class" rather than Class, or that we use ** for
exponentiation rather than ^.
> probably works for 0 and 1 also but you probably wouldn't consider
> testing thing is 1, at least I hope you wouldn't. thing is None looks
> just as odd to me. Why not thing == None ? That works.
It is wrong (in other words, it doesn't work) because it allows non-None
objects to masquerade as None and pretend to be what they are not.
If that's your intent, then of course you may do so. But without a
comment explaining your intent, don't be surprised if more experienced
Python programmers correct your "mistake".
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list