issubclass
Check whether a class is a subclass of another class.
Python 3.13
issubclass(class, classinfo)- class
- The class to check.type
- classinfo
- A class, a tuple of classes or a union such as int | float: any of them matches.type | tuple | UnionType
Return value
True if class inherits from classinfo or is the same class, otherwise False.
Examples
Checking class inheritance
Python 3.13
class A:
pass
class B(A):
pass
print(issubclass(B, A))
print(issubclass(A, B))True False
A tuple of classes and the class itself
Python 3.13
print(issubclass(bool, (int, float)))
print(issubclass(int, int))True True
Details
A class is considered a subclass of itself: issubclass(int, int) gives True. Passing an instance instead of a class raises TypeError.
