Menu Close

Python issubclass() Function

python issubclass function

Hi Python programmer, In this guide, we are going through the Python issubclass function to check if a specified object is a subclass of a specified object. This python built-in function returns only Boolean value which means True or False.

In previous tutorials, we have seen all about the isinstance() function to check a specified object is of specified object.

Python issubclass() function

issubclass function is a part of Python built-in functions that are 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 returns False.

Syntax

The syntax of the 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 and understand the 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))

The 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 a 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.

For more information:- Click Here

Python complex() Function
Python bool() Function

Related Posts