# How do we check if a class is a subclass of the given super class in Python?

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

We have the classes A and B defined as follows −

class A(object): pass
class B(A): pass

B can be proved to be a sub class of A in two ways as follows

class A(object):pass
class B(A):pass
print issubclass(B, A) # Here we use the issubclass() method to check if B is subclass of A
print B.__bases__ # Here we check the base classes or super classes of B

This gives the output

True
(<class '__main__.A'>,)
Updated on 13-Jun-2020 13:52:45