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 Dictionary popitem()
Python while Loop
Python Program to Add Two Matrices
Python List insert()
Python memoryview()
Python Program to Convert Bytes to a String
Python Program to Convert Celsius To Fahrenheit
Python setattr()
Python Tuple index()
Python Dictionary items()
Python Program to Capitalize the First Character of a String
How to get current date and time in Python?
Python del Statement
Python Program to Sort Words in Alphabetic Order
Python Exception Handling Using try, except and finally statement
Python Program to Check Leap Year
Python String format_map()
Python Program to Count the Number of Digits Present In a Number
Python Namespace and Scope
Python compile()
Python Program to Find the Largest Among Three Numbers
Python sorted()
Python String replace()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Get the File Name From the File Path
Python Program to Check if a Number is Odd or Even
Python Program to Append to a File
Python hasattr()
Python type()
Python Tuple count()
Python RegEx