Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / chaitanya

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 given as isinstance(obj,cls) and in more details given as:

isinstance(obj, (class1, class2, ...)) that is used to check about 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)).

It is not preferred to use the class instead user-defined classes are made that allow easy object-oriented style to define the behavior of the object’s class. These perform different thing that is based on the class. The function differs from one class to another class. To find out the object of the particular class the following program is used:

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.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does range start at 0 python?

776


Are tuples mutable?

796


Explain python is one line?

759


How will you remove all leading and trailing whitespace in string in python?

794


How do you perform pattern matching in python?

902


Who built the sphinx?

747


What is numpy shape?

765


When you need ordered container of things, which will be manipulated, use lists?

1053


What are some common uses of Pickling in Python?

765


Why pypy is faster than python?

761


Why is lambda used in python?

911


Is string immutable ?

775


In Python what are iterators?

913


How to declare the variables function in python?

984


What is class in python?

935