If I define a class in Python such as:
class AClass:
__slots__ = ['a', 'b', 'c']
Which class does it inherit from? It doesn't seem to inherit from object
.
Try the following code snippet in Python 2.7 and Python 3.1
class AClass:
__slots__ = ['a', 'b', 'c']
print(type(AClass))
print(issubclass(AClass,object))
print(isinstance(AClass,type))
In Python 2.7, you will get:
<type 'classobj'>
False
False
And Python 3.1 you will get.
<class type>
True
True
And that explains it all. It is old style class in Python 2, unless you subclass it from object
. Only in Python3, it will be treated like a new style class by default.
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