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 Dictionary fromkeys()
Python Set union()
Python Program to Display Powers of 2 Using Anonymous Function
Python Input, Output and Import
Python Dictionary items()
Python Dictionary get()
Python __import__()
Python String format_map()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python *args and **kwargs
Python Program to Capitalize the First Character of a String
Python Program to Get File Creation and Modification Date
Python hash()
Python Package
Python Program to Find Factorial of Number Using Recursion
Python Program to Append to a File
Python float()
Python compile()
Python Set difference()
Python Program to Trim Whitespace From a String
Python Program to Print all Prime Numbers in an Interval
Python Iterators
Python classmethod()
Python timestamp to datetime and vice-versa
Python str()
Python chr()
Python Program to Add Two Matrices
Python frozenset()
Python print()
Python round()
Python Namespace and Scope