Defining Class Methods with the def Statement : Class Definition : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Class Definition »

 

Defining Class Methods with the def Statement


class Account:
    def initAccount(acct, AcName, OpenDate, Balance=0.0):
        acct.OpenDate = OpenDate
        acct.AcName = AcName
        acct.Balance = Balance
        acct.History = []

    def processTransaction(acct, date, amount, reason):
        acct.Balance = acct.Balance + amount
        acct.History.append((date, amount, reason)) 

Current = Account()
Account.initAccount(Current, "Checking Account""2008-11-26"1234.56)
Account.processTransaction(Current, "2008-11-26", -1000.00"Cash Withdrawal")
print "%8.2f" % Current.Balance



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Class Definition