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:
True
if class is subclass of a class, or any element of the tupleFalse
otherwise
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 Inheritance
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Dictionary setdefault()
Python Program to Parse a String to a Float or Int
Python for Loop
Python Program to Create a Long Multiline String
Python Program to Solve Quadratic Equation
Python strftime()
Python Tuple
Python bytearray()
Python bin()
Python Dictionary values()
Python Dictionary pop()
Python Program to Illustrate Different Set Operations
Python Program to Check If Two Strings are Anagram
Python Program to Convert Two Lists Into a Dictionary
Python Set difference_update()
Python Dictionary update()
Python Program to Randomly Select an Element From the List
Python round()
Python Program to Iterate Through Two Lists in Parallel
Python next()
Python pow()
Python String count()
Python sorted()
Python String rstrip()
Python Numbers, Type Conversion and Mathematics
Python Set intersection()
Python object()
APIs in Node.js vs Python - A Comparison
Python String rpartition()
Python Modules