Q What is __init__
doing or storing?
A __init__
gets called whenever you construct an instance of the class. This applies to all classes. It is customary to initialize all your data in this function. In your particular case, you are creating a member data called amount
and assigning it to be the same as the deposit
argument passed to the function.
Q I don't understand what "self.amount"
is or how making it = deposit
does anything.
A The statement self.amount = deposit
accomplishes couple of things. It creates a member data of the class named amount
and assigns it to be the value of deposit
.
Q Is the "self.amount"
under __init__
the same as the one under withdraw?
A Yes.
Q I'm just not understanding what "self.amount"
does.
A It allows you to capture the data of the object. Every class needs to figure out member data it needs to work correctly. In your case, the only data you need is the amount
. If you had a class called Employee
, it might look something like:
class Employee(object):
def __init__(self, firstName, lastName, id, salary):
self.firstName = firstName
self.lastName = lastName
self.id = id
self.salary = salary