What is the issubclass() method in Python?
The issubclass() method is used to determine if a class is a subclass of a specified class.
- It returns
Trueif a class is a subclass of the specified class - It returns
Falseif a class is not a subclass of the specified class
classinfo can be specified as a tuple of class objects. In that case, every entry in classinfo is checked.
isubclass()returnsTrueif class is a subclass of any element in the tuple.
Code
In the code below, we check if the Kiwi class is a subclass of the Fruit class. Since it is, issubclass() returns True.
class Fruit:def __init__(fruittype):print(fruittype)class Kiwi(Fruit):def __init__(self):Fruit.__init__('Kiwi')print(issubclass(Kiwi, Fruit))
In the following code snippet, we check if Kiwi is a subclass of Fruit and Vegetable. Since Kiwi is a subclass of Fruit, issubclass() returns True.
class Fruit:def __init__(fruittype):print(fruittype)class Vegetable:def __init__(vegetabletype):print(fruittype)class Kiwi(Fruit):def __init__(self):Fruit.__init__('Kiwi')print(issubclass(Kiwi, (Fruit, Vegetable)))
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved