Python issubclass() function

Published February 16, 2022

The Python issubclass() function is a built-in function that determines whether a specified class is a subclass of another class. The Python issubclass() function returns true if the class specified in the first argument is a subclass of the class given in the second argument and false otherwise.

The issubclass() Syntax
The  syntax of the issubclass is:

issubclass(class, classdescription)

where
class: is the class to be reviewed
classdescription:  lists the class, class turple , class type

Example

class Course:
    def __init__(CourseType):
        print('Course is a ', CourseType)
class Student(Course):
    def __init__(self):
        Course.__init__('Student')
print(issubclass(Student, Course))
print(issubclass(Student, list))
print(issubclass(Student, (list, Course)))
print(issubclass(Student, (list, Course)))


Output

True
False
True
True

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

237 Views