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 String index()
Python Set copy()
Python globals()
Python Dictionary clear()
Python int()
Python List extend()
Python Program to Print Output Without a Newline
Python tuple()
Python Program to Find the Size (Resolution) of a Image
Python Program to Get the Class Name of an Instance
Python pass statement
Python Program to Return Multiple Values From a Function
Python String casefold()
Python Program to Represent enum
Python Program to Safely Create a Nested Directory
Python Set discard()
Python String isupper()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python callable()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Concatenate Two Lists
Python Program to Make a Simple Calculator
Python Dictionary values()
Python String isdigit()
Python frozenset()
Python memoryview()
Python Dictionary popitem()
Python Program to Create a Long Multiline String
Python Program to Print Colored Text to the Terminal
Python Set isdisjoint()
Deep Learning in Python - LazyProgrammer
Python enumerate()