How will you check if a class is a child of another class?

- This is done by using a method called issubclass() provided by python. The method tells us if any class is a child of another class by returning true or false accordingly.
- We can check if an object is an instance of a class by making use of isinstance() method:

Example:

class Parent():
pass

class b(Parent):
pass
print(issubclass(b,Parent)) #true
print(issubclass(Parent,b)) #False

obj1=b()
obj2=Parent()
print("=======")
print(isinstance(obj2,b)) #False
print(isinstance(obj2,Parent)) #True
THANKS!!

Comments

Popular posts from this blog

Python namespaces & LEGB rule in Python