答案 0 :(得分:3)
是的,在Python2和Python3中:
>>> type(None)
<class 'NoneType'>
>>> type(None).mro()
[<class 'NoneType'>, <class 'object'>]
>>> issubclass(type(None), object)
True
>>> isinstance(None, object)
True
请注意,在Python2中,不是object
的子类的仅类是旧式类。但是,此类的实例仍然是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
编辑:我怀疑Python的某些内容可能会有所不同。 2.6并且可能用于在C中实现的类型。
答案 1 :(得分:1)
答案 2 :(得分:1)
是的,虽然我只能测试版本3.4
Python 3.4.3 (default, May 5 2015, 17:58:45)
[GCC 4.9.2] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> None.__class__
<class 'NoneType'>
>>> issubclass(None.__class__, object)
True