Python issubclass() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in

Definition

In Python, issubclass(cls, base) returns True if the class cls inherits from base, directly or through other classes. A class counts as a subclass of itself, so issubclass(int, int) is True.

Like isinstance(), it accepts a tuple of base classes and returns True if any of them match. The difference is that issubclass() works on classes, while isinstance() works on instances.

issubclass() is a built-in function: it lives in the builtins module, so it is always available without an import.

Syntax

Both arguments are classes (the second may be a tuple).

python
ok = issubclass(ChildClass, BaseClass)
ok = issubclass(ChildClass, (BaseA, BaseB))
CallWhat it does
issubclass(bool, int)Returns True.
issubclass(int, bool)Returns False.
issubclass(KeyError, LookupError)Returns True.
issubclass(int, int)Returns True: a class is its own subclass.

To see the full chain of parents in order, look at SomeClass.__mro__.

Library declarations
python
issubclass(class, classinfo, /)

Parameters

ParameterDescription
classRequired. The class to test (not an instance).
classinfoRequired. A class, a tuple of classes, or on 3.10+ a union like int | str.

Return Value

Return ValueDescription
boolTrue if class derives from classinfo.

Python Examples

Example 1 — Subclass Checks with Built-in Types

Test relationships between bool, int, object, and exception classes.

python
print(issubclass(bool, int))
print(issubclass(int, bool))
print(issubclass(int, object))
print(issubclass(int, int))
print(issubclass(ValueError, (KeyError, Exception)))

How It Works

  1. One direction only. bool inherits from int, but int does not inherit from bool.
  2. Everything reaches object. Every class is a subclass of object.
  3. Reflexive. A class is considered a subclass of itself.
  4. Tuple of bases. ValueError is not a KeyError, but it is an Exception, so the result is True.

Example 2 — Find the Family of Each Exception

Check which broad exception family several specific errors belong to.

python
for err in [KeyError, ZeroDivisionError, FileNotFoundError]:
    parents = [
        base.__name__
        for base in (LookupError, ArithmeticError, OSError)
        if issubclass(err, base)
    ]
    print(err.__name__, "->", parents)

print(issubclass(IndexError, LookupError))

How It Works

  1. Classes as values. Exception classes can be stored in a list and looped over.
  2. Family membership. Each specific error belongs to exactly one of the three families tested.
  3. Why it matters. except LookupError: catches both KeyError and IndexError.
  4. Readable report. __name__ prints class names without the <class ...> wrapper.

Example 3 — A Three-Level Class Hierarchy

Check indirect inheritance, inspect the MRO, and pass an instance by mistake.

python
class Vehicle:
    pass


class Car(Vehicle):
    pass


class ElectricCar(Car):
    pass


print(issubclass(ElectricCar, Vehicle))
print(issubclass(Vehicle, Car))
print([cls.__name__ for cls in ElectricCar.__mro__])

try:
    issubclass(Car(), Vehicle)
except TypeError:
    print("issubclass() needs a class, not an instance")

How It Works

  1. Indirect inheritance. ElectricCar reaches Vehicle through Car.
  2. Parents are not children. Vehicle is not a subclass of Car.
  3. The MRO. __mro__ lists every class that is checked, from the class itself up to object.
  4. Instance by mistake. Car() is an object, not a class, so Python raises TypeError.

Frequently Asked Questions

issubclass() compares two classes; isinstance() checks whether an object is an instance of a class.
Yes. issubclass(C, C) is always True.
Yes, pass a tuple: issubclass(cls, (A, B)) is True if cls derives from either.
The first argument must be a class. Use isinstance(obj, base) or issubclass(type(obj), base) for objects.
Look at cls.__mro__, which lists the class and all its ancestors in method resolution order.

Next: iter()

Get an iterator from an iterable, or from a callable and a sentinel.

iter() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful