all Python 3Built-in functionsterm
issubclass
introspection/OOP
Returns True if the class is a subclass of the given class or of one of the classes in the tuple.
Syntax
issubclass(class, classinfo)
The first argument must be a class, not an instance — passing an object raises TypeError, and objects are checked with isinstance instead. The second argument may be a tuple of classes, in which case inheriting from any one of them is enough. Watch out for bool: it is a subclass of int, so a check against int also accepts True and False.
Examples
print(issubclass(bool, int)) # → True
print(issubclass(int, object)) # → True
print(issubclass(list, (list,tuple))) # → True
class A: pass
class B(A): pass
print(issubclass(B, A)) # → True
print(issubclass(A, B)) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy