Issubclass () function in Python

The built-in issubclass () function checks whether an object (first parameter) is a subclass of classinfo (the second parameter).

The issubclass () function syntax in Python

 issubclass(object, classinfo) 

Parameters of issubclass function ()

Issubclass () has 2 parameters:

  1. object : object to check
  2. classinfo : class, type, or tuple

Value returned from issubclass ()

Function issubclass () returns:

  1. True if the object is a subclass subclass of the class or any element of the tuple.
  2. False if vice versa.

Example: How is issubclass () function?

 class DaGiac: def __init__(loaiDagiac): print('Da giac la ', loaiDagiac) class TamGiac(DaGiac): def __init__(self): DaGiac.__init__('tamgiac') print(issubclass(TamGiac, DaGiac)) print(issubclass(TamGiac, list)) print(issubclass(TamGiac, (list, DaGiac))) print(issubclass(DaGiac, (list, DaGiac))) 

Run the program, the result is:

 True False True True 

Note that the class is also considered a subclass of itself.

See also: Built-in Python functions

5 ★ | 2 Vote

May be interested

  • Regular Expression (RegEx) in PythonPhoto of Regular Expression (RegEx) in Python
    regular expression (regex), also known as regular expression, is a segment of special characters that follow certain patterns.
  • Declare @property in PythonPhoto of Declare @property in Python
    going back to the advanced python lessons, today tipsmake.com will work with you to learn about @property (decorator) declarations.
  • Decorator in PythonPhoto of Decorator in Python
    decorator is used a lot in python. so how to create a decorator and why you should use it. let's go find the answer!
  • How to use Closure in PythonPhoto of How to use Closure in Python
    in this article, tipsmake.com will work with you to learn about closure in python, how to define a closure and why you should use it. let's go find the answer!
  • Function sleep () in PythonPhoto of Function sleep () in Python
    module time in python provides some very useful functions to handle time-related tasks. one of the most commonly used functions is sleep ().
  • Generator in PythonPhoto of Generator in Python
    how is the generator different from iterator and what is the usual function, why should we use it? let's find out all through this article.