issubclass()

Check if the input object is subclass of input classinfo.

class : class to be checked for subclass against classinfo
classinfo : class to be checked against this classinfo. Can be a tuple of more than one class

issubclass returns True if class is subclass of given classinfo, False otherwise.
issubclass(class ,classinfo)
We created a parent ( base ) class animals(), then we derived sub class or child class wild(). Then we created birds() as child class of wild()

We will use issubclass() to check our classes against different classinfo.
class animals():
    home='Jungle' #class attribute
#instance attributes
    def __init__(self,name,height):
        self.name= name
        self.height=height
class wild(animals):
    weight=2
class birds(wild):
    name='Eagle'

print(issubclass(wild,animals))  # True
print(issubclass(birds,wild))    # True
print(issubclass(birds,animals)) # True
print(issubclass(animals,wild))  # False
print(issubclass(wild,wild))     # True
print(issubclass(wild,(str,list,animals))) # True

Using tuple

Check the last line of above code , we used one tuple to check the class against more than one classinfo . Here it is again
print(issubclass(wild,(str,list,animals))) # True

Using isinstance()

By using isinstance() we can check if the object is instance of the class or not.

All Built in Functions in Python locals() dir() classmethod
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer