13.11. Built-in Functions for Classes, Instances, and Other Objects
13.11.1. issubclass()
The issubclass() Boolean function determines if one class is a subclass or descendant of another class. It has the following syntax:
issubclass(sub, sup)
issubclass() returns 1 if the given subclass sub is indeed a subclass of the superclass sup. This function allows for an “improper” subclass, meaning that a class is viewed as a subclass of itself, so the function returns 1 if sub is either the same class as sup or derived from sup. (A “proper” subclass is strictly a derived subclass of a class.)
If we were to implement the issubclass() built-in function ourselves, it may look something like the following:
def my_issubclass(sub, sup): if sub is sup ...
Get Core Python Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.