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): name
class wild(animals):
class birds(wild):

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
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    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 FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer