Hi Python programmer, In this guide, we are going through the python issubclass function to check a specified object is a sub class of a specified object. This python built-in function returns only Boolean value that means True or False.
In previous tutorials, we have seen all about the Python isinstance() function to check a specified object is of the specified object.
Table of Contents
Python issubclass() function
Python issubclass function is a built-in function in python that is used to check a specified object is a subclass of the specified object.
issubclass function in python return True, if the specified object is a subclass of a specified object otherwise return False.
Syntax
The syntax of Python issubclass function is:-
issubclass(object, subclass)
Parameter
issubclass function in python accepts only two parameters.
- object:- Required. An object.
- subclass:- A class object, or a tuple of class objects.
Return Value
The return value of issubclass function in python is only True or False.
Python issubclass examples
Let’s see understand python issubclass function along with simple examples.
Example:
#Parent class
class Computer:
name = 'Desktop'
#subclass of parent class
class Laptop(Computer):
name2 = 'Laptop'
#check whether Laptop is a subclass of Computer
print(issubclass(Laptop, Computer))
Output will be:- True
Conclusion
In the article, you have learned all about Python issubclass function to check a specified object is a subclass of the specified object. This function returns only True or False value. Click here to learn all python built-in functions tutorials.
If you like this article, please share and keep visiting for further python tutorials.
Python built-in functions
For more information:- Click Here