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 Program to Print Output Without a Newline
Python Data Types
Python hash()
Python slice()
Python String ljust()
Python Program to Make a Simple Calculator
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Display Fibonacci Sequence Using Recursion
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python frozenset()
Python str()
Python help()
Python Get Current time
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Dictionary get()
Python Program to Print the Fibonacci sequence
Python Type Conversion and Type Casting
Python String index()
Python range()
Deep Learning in Python - LazyProgrammer
Python del Statement
Python Recursion
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Global Keyword
Python min()
Python delattr()
Python abs()
Python Program to Merge Two Dictionaries
Python String zfill()
Python String swapcase()
Python break and continue
Python locals()