the _init_ method in python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dynamo
    New Member
    • Apr 2007
    • 51

    the _init_ method in python

    class ChargingAccount (BankAccount):
    def __init__(self, initialAmount):
    BankAccount.__i nit__(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.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by dynamo
    class ChargingAccount (BankAccount):
    def __init__(self, initialAmount):
    BankAccount.__i nit__(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.

    Comment

    • dynamo
      New Member
      • Apr 2007
      • 51

      #3
      Thanks for replying to my query.

      Comment

      Working...