Why inheriting from object makes big differences in Python?
When class is inherited from nothing, I have an object of instance type.
>>> class A(): pass;
>>> a = A()
>>> type(a)
<type 'instance'>
>>> type(a) is A
False
>>> type(A)
<type 'classobj'>
However, when I have the same class inheriting from an object, the created
object is type of A.
>>> class A(object): pass;
>>> a = A()
>>> type(a)
<class '__main__.A'>
>>> type(a) is A
True
>>> type(A)
<type 'type'>
What is the logic behind this? Does this mean every class should inherit
from object?
No comments:
Post a Comment