ScanSkill

issubclass

This issubclass() function returns a Bool type indicating whether an object is a subclass of a class.

Syntax

issubclass(object, classinfo)

Here,

  • object: Required. An object.
  • classinfo: Required. A class, type, or a tuple containing classes and types

Note: A class is considered a subclass of itself. 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*.***

Examples

>>> class Class1:
...     pass
... 
>>> class Class2(Class1):
...     pass
... 
>>> class Class3:
...     pass
... 
>>> a = Class2()
>>> issubclass(Class2, Class1)
True
>>> issubclass(Class2, Class3)
False
>>> issubclass(Class1, Class1)
True
>>> issubclass(Class2, (Class1, Class3))
True