[Tutor] Class question
Sean 'Shaleh' Perry
shaleh@valinux.com
Thu, 29 Jun 2000 13:56:20 -0700 (PDT)
>
> class BankAccount:
> def _init_(self, initialAmount):
> self.balance = initialAmount
> print "Account created with balance %5.2f" %self.balance
>
> def deposit(self, amount):
> self.balance = self.balance + amount
>
> def checkBalance(self):
> return self.balance
>
a) it is __init__()
b) your e-mail does not reflect proper code layout. Whitespace is important to
python, it is how the interpreter knows which piece of code goes where.
class BankAccount:
def __init__(self, initialAmount):
self.balance = initialAmount
print "Account created with balance %5.2f" % (self.balance) # % tuple
def deposit(self, amount):
self.balance = self.balance + amount
def checkBalance(self):
return self.balance
when you are unsure of a problem, launch python and just type code into the
interpreter.