Checking whether type is None

David Raymond David.Raymond at
Tue Jul 24 15:56:54 EDT 2018

The sole value of the type NoneType..."

"x is None" and "type(x) is type(None)" are equivalent because of that.

I think though that the better way to do the first tests would be to use isinstance

isinstance({}, dict)
isinstance(3, int)

And I suppose if you really wanted:
isinstance(None, type(None))

-----Original Message-----
From: Python-list [ at] On Behalf Of Tobiah
Sent: Tuesday, July 24, 2018 3:33 PM
To: python-list at
Subject: Checking whether type is None


	>>> type({}) is dict
	>>> type(3) is int
	>>> type(None) is None

Obvious I guess, since the type object is not None.
So what would I compare type(None) to?

	>>> type(None)
	<type 'NoneType'>
	>>> type(None) is NoneType
	Traceback (most recent call last):
	  File "<stdin>", line 1, in <module>
	NameError: name 'NoneType' is not defined

I know I ask whether:

	>>> thing is None

but I wanted a generic test.
I'm trying to get away from things like:

	>>> type(thing) is type(None)

because of something I read somewhere preferring
my original test method.


More information about the Python-list mailing list