In Python, a class is considered as the subclass of itself.
Python issubclass() Syntax
issubclass() takes two parameters.
- class (required) – a class that is to be checked
- classinfo (required) – a class, type or a tuple of classes or types
issubclass(class, classinfo) function will return
true if and only if the class is a subclass of
classinfo, else it will return
Python issubclass() Example
>>> class Car: pass >>> class Buggati(Car): pass >>> issubclass(Buggati, Car) True >>> issubclass(Car, Buggati) False >>> #checking if a class is subclass of itself >>> issubclass(Car, Car) True
Seems pretty much same as Python
isinstance() function. So what is the difference?
Difference between Python issubclass() and isinstance()
The difference is basic.
isinstance(object, classinfo) basically checks whether or not the object is an instance or subclass of
issubclass(class, classinfo) checks whether or not a class is subclass of