Python 3 reference · Built-in Functions
Python issubclass() Function
Return True if a class is a subclass of another class (or of any class in a tuple or union). A class is a subclass of itself.
Python 3 Since 3.0
Syntax
issubclass(class, classinfo)
Parameters
| Parameter | Description |
|---|---|
class |
The class to check. |
classinfo |
A class, tuple of classes, or union. |
Return value
True or False.
Examples
class Animal: pass
class Dog(Animal): pass
print(issubclass(Dog, Animal), issubclass(Animal, Dog))
print(issubclass(Dog, Dog))
Output
True False True
print(issubclass(bool, int), issubclass(int, (str, float)))
from collections.abc import Sequence
print(issubclass(list, Sequence), issubclass(dict, Sequence))
Output
True False True False
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
| Python 3.10 | classinfo can be a union type. |
Related
isinstance()· Return True if an object is an instance of a class, one of its subclasses, or any class in a tuple or union of classes.type()· With one argument, return an object's type. With three arguments, create a new class dynamically.super()· Return a proxy that calls methods of the parent class, so a subclass can extend a method instead of replacing it.- Python Inheritance · tutorial