Write a program to check whether the object is of a class or its subclass.

Technology CommunityCategory: PythonWrite a program to check whether the object is of a class or its subclass.
VietMX Staff asked 3 years ago

There is a method which is built-in to show the instances of an object that consists of many classes by providing a tuple in a table instead of individual classes. The method is isinstance(obj,cls)

isinstance(obj, (class1, class2, ...)) is used to check the object’s presence in one of the classes. The built in types can also have many formats of the same function like isinstance(obj, str) or isinstance(obj, (int, long, float, complex)):

def search(obj):
  if isinstance(obj, box):
  # This is the code that is given for the box and write the program in the object
  elif isinstance(obj, Document):
  # This is the code that searches the document and writes the values in it
  elif

obj.search()
#This is the function used to search the object’s class.