issubclass()
Anonymous contributor
Anonymous contributor1 total contribution
Anonymous contributor
Published Mar 27, 2023
Contribute to Docs
The issubclass()
function returns a boolean indicating whether a given class is a subclass of one or more classes.
Syntax
issubclass(class, candidateClasses)
issubclass()
take two parameters:
class
: A validly defined class.candidateClasses
: A single class or type, or a tuple of classes and types.
If class
is a subclass of candidateClasses
(direct or indirect), True
is returned, False
otherwise.
Example
The following example uses the issubclass()
function to confirm whether myInfo
is a subclass of the myAge
class:
class myAge:age = 36class myInfo(myAge):name = "Homer"age = myAgeprint(issubclass(myInfo, myAge))
This will print the following output:
True
Codebyte Example
In the following example, the issubclass()
function checks the relationship between the Car
and Color
classes. While Color
is a subclass of Car
, the reverse is not true:
All contributors
- Anonymous contributorAnonymous contributor1 total contribution
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.