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...

Explain how to overload constructors (or methods) in Python.

Answer Posted / chaitanya

_init__ () is a first method defined in a class. when an instance of a class is created, python calls __init__() to initialize the attribute of the object.

Following example demonstrate further:

class Employee:

def __init__(self, name, empCode,pay):

self.name=name

self.empCode=empCode

self.pay=pay

e1 = Employee("Sarah",99,30000.00)

e2 = Employee("Asrar",100,60000.00)

print("Employee Details:")

print(" Name:",e1.name,"Code:", e1.empCode,"Pay:", e1.pay)

print(" Name:",e2.name,"Code:", e2.empCode,"Pay:", e2.pay)

---------------------------------------------------------------

Output

Employee Details:

(' Name:', 'Sarah', 'Code:', 99, 'Pay:', 30000.0)

(' Name:', 'Asrar', 'Code:', 100, 'Pay:', 60000.0)

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is node better than python?

800


What is python basic syntax?

807


What are the file-related modules we have in python?

866


What is the meaning of def in python?

918


What language is python based on?

835


How does exception handling in python differ from java?

827


What is orm in python?

814


What is the usage of help() function in python?

810


How many variables are in python?

809


Can I create apps with python?

765


Do we need to call the explicit methods to destroy the memory allocated in python?

1362


What happens when you execute the statement mango=banana in python?

872


What are class methods?

762


Why is not__getattr__invoked when attr==’__str__’?

943


Write the command to get all keys from the dictionary.

757