Python issubclass() Function
Python issubclass() Function
The issubclass() function in Python returns a boolean value ‘True’ if the given object is a subclass of classinfo, else it returns False.
Syntax
issubclass(class, classinfo)
Parameter
class: It is a required parameter which represents a tuple of class objects.
classinfo: This parameter represents a type or a class, or a tuple of types and/or classes
Return
This function returns True if the given object is a subclass of the specified object, else it returns False.
Example 1
# Python Program explaining # the issubclass() function class Score: score = 136 class Obj(Score): name = "Reema" score = Score val = issubclass(Score, Obj) print(val)
Output
False
Example 2
# Python Program explaining
# the issubclass() function
class Shape:
def __init__(polygonType):
print('Polygon is a ', polygonType)
class Triangle(Shape):
def __init__(self):
Polygon.__init__('triangle')
print(issubclass(Triangle, Shape))
print(issubclass(Triangle, list))
print(issubclass(Triangle, (list, Shape)))
Output
True False True True
