Check if a class is a subclass of another using issubclass() function

PHOTO EMBED

Tue Jun 18 2024 03:27:39 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds

class Person:
    def __init__(self, name, age):
       self.name = name
       self.age = age

class Student(Person):
     def __init__(self, name, age, school):
        super().__init__(name, age)
        self.school = school

#Check whethe a class is a  subclass of another
print(issubclass(Student, Person))
content_copyCOPY

https://www.pynerds.com/python-issubclass-function/