Python: issubclass() function
issubclass() function
The issubclass() function returns true if the specified object is a subclass of the specified object, otherwise false. A class is considered a subclass of itself.
Version:
(Python 3.2.5)
Syntax:
issubclass(class, classinfo)
Parameter:
Name | Description | Required / Optional |
---|---|---|
class | An object to be checked. | Required |
classinfo | classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, a TypeError exception is raised. | Required |
Example: Python issubclass() function
class Square:
def __init__(SquareType):
print('Square is a ', SquareType)
class Rectangle(Square):
def __init__(self):
Square.__init__('Rectangle')
print(issubclass(Rectangle, Square))
print(issubclass(Rectangle, list))
print(issubclass(Rectangle, (list, Square)))
print(issubclass(Square, (list, Square)))
Output:
True False True True
Python Code Editor:
Previous: isinstance()
Next: iter()
Test your Python skills with w3resource's quiz
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics