For user-defined type X
,
>>> class X(object):
... pass
...
>>> issubclass(X, object) # User-defined type
True
>>> isinstance(X, object) # User-defined type
True
Q) How X
behaves as both sub class and instance of object
?
>>> issubclass(int, object) # Built-in type
True
>>> isinstance(int, object) # Built-in type
True
Q) How int
behave as both sub class and instance of object
?
>>> issubclass(type, object) # Meta class
True
>>> isinstance(type, object) # Meta class
True
Q) How type
can be both, sub class and instance of object
?
>>> issubclass(object, type)
False
>>> isinstance(object, type)
True
object
not being sub class but instance of type
, which makes sense
>>> issubclass(int, type)
False
>>> isinstance(int, type)
True
>>>
int
not being sub class but instance of type
, makes sense.
>>> issubclass(X, type) # User-defined type
False
>>> isinstance(X, type) # User-defined type
True
also makes sense.
Edit:
here it says, The major motivation for introducing new-style classes is to provide a unified object model with a full meta-model.
Q) How to understand the meaning of unified object model?
Q) What is meta-model?
Q) What does it mean to say, type
instance of type
?
All three of your questions come down to "how can X be both a subclass and instance of object
". The answer is simple: everything is a subclass of object
. Classes are objects (=instances of object
), and hence, subclasses (including subclasses of object
) are also instances of object
.
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