1.

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

Answer»

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.
For example:

class PARENT(object): pass class Child(Parent): pass # Driver Codeprint(issubclass(Child, Parent)) #Trueprint(issubclass(Parent, Child)) #False
  • We can check if an object is an INSTANCE of a class by making use of isinstance() method:
obj1 = Child()OBJ2 = Parent()print(isinstance(obj2, Child)) #False print(isinstance(obj2, Parent)) #True


Discussion

No Comment Found