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

Explain how memcached should not be used in your python project?

980


Does python support object oriented scripting?

917


Do you know why lambda forms in python does not have statements?

1038


Is nan a float python?

847


Explain me what are the built-in types available in python?

835


In python, how do I check if a list is empty?

873


What is def __ init __ in python?

931


How do you create a list which is a reverse version on another list in python?

901


What is the best ide for python?

940


Is geany a good ide?

803


Is dictionary faster than list python?

791


Why is numpy so fast?

935


What is a docstring?

892


Is java or python more useful?

845


How many variables are in python?

858