By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

the _init_ method in python

P: 51
class ChargingAccount(BankAccount):
def __init__(self, initialAmount):
BankAccount.__init__(self, initialAmount)
in the above sample bank account is the parent class,i think i understand why the init method is being called from bankaccount,to be able to use self,initial amount from bankaccount right?But if that is so why is it initialised in the child class before initialising it again on the second line.
Mar 27 '08 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
class ChargingAccount(BankAccount):
def __init__(self, initialAmount):
BankAccount.__init__(self, initialAmount)
in the above sample bank account is the parent class,i think i understand why the init method is being called from bankaccount,to be able to use self,initial amount from bankaccount right?But if that is so why is it initialised in the child class before initialising it again on the second line.
Please use code tags when posting code. See Posting Guidelines.

An instance of a class is created by calling a class object as a function. The static method __new__() is called to create an instance which, in turn, calls the __init__() method of a class. The __init__() method call initializes the contents of an instance. Instance attributes and methods of class BankAccount() would not be available to an instance of ChargingAccount() unless its __init__() method was explicitly called. I hope this makes sense.
Mar 27 '08 #2

P: 51
Thanks for replying to my query.
Apr 4 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.