w3resource

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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python/built-in-function/issubclass.php