Table of Contents
The issubclass() function checks if the class argument (first argument) is a subclass of classinfo class (second argument).
The syntax of issubclass() is:
issubclass(class, classinfo)
1. issubclass() Parameters
issubclass() takes two parameters:
- class – class to be checked
- classinfo – class, type, or tuple of classes and types
2. Return Value from issubclass()
issubclass() returns:
Trueif class is subclass of a class, or any element of the tupleFalseotherwise
3. Example: How issubclass() works?
class Polygon:
def __init__(polygonType):
print('Polygon is a ', polygonType)
class Triangle(Polygon):
def __init__(self):
Polygon.__init__('triangle')
print(issubclass(Triangle, Polygon))
print(issubclass(Triangle, list))
print(issubclass(Triangle, (list, Polygon)))
print(issubclass(Polygon, (list, Polygon)))
Output
True False True True
It’s important to note that class is considered a subclass of itself.
Related posts:
Python type()
Python Tuple count()
Python Program to Count the Occurrence of an Item in a List
Python dir()
Python Program to Get Line Count of a File
Python str()
Python Program to Find the Largest Among Three Numbers
Python float()
Python Program to Catch Multiple Exceptions in One Line
Python Set discard()
Python Keywords and Identifiers
Python Program to Convert Two Lists Into a Dictionary
Python bytearray()
Python Program to Find the Size (Resolution) of a Image
Python @property decorator
Python Program to Check If Two Strings are Anagram
Python Dictionary values()
Python strptime()
Python id()
Python Generators
Python strftime()
Python Program to Find LCM
Python Program to Trim Whitespace From a String
Python Shallow Copy and Deep Copy
Python Program to Add Two Numbers
Python Data Types
Python for Loop
Python Program to Differentiate Between type() and isinstance()
Python input()
Python Program to Print all Prime Numbers in an Interval
Python all()
Python Program to Print Colored Text to the Terminal