In the below class hierarchy,

Does class NoneType inherits class object?
Note : python 3.5
Yes, in both Python2 and Python3:
>>> type(None)
<class 'NoneType'>
>>> type(None).mro()
[<class 'NoneType'>, <class 'object'>]
>>> issubclass(type(None), object)
True
>>> isinstance(None, object)
True
Note that in Python2, the only classes that are not subclasses of object are old-style classes. However, instances of such classes are still instances of object:
>>> class Foo:
... pass
...
>>> foo = Foo()
>>> foo
<__main__.Foo instance at 0x7f2a33474bd8>
>>> type(foo)
<type 'instance'>
>>> foo.__class__
<class __main__.Foo at 0x7f2a33468668>
>>> Foo.mro()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: class Foo has no attribute 'mro'
>>> issubclass(Foo, object)
False
>>> isinstance(foo, object)
True
>>> type(foo).mro()
[<type 'instance'>, <type 'object'>]
>>> issubclass(type(foo), object)
True
Edit: I suspect some things might be different for Python < 2.6 and possibly for types implemented in C.
Yes.
The isinstance function can tell you this.
>>> isinstance(None, object)
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With