eEcho blog

is een halte van de gedachte

Python Classes

Declaratie:
class Account:
   def __init__(self, initial):
      self.balance = initial
   def deposit(self, amt):
      self.balance = self.balance + amt
   def withdraw(self,amt):
      self.balance = self.balance - amt
   def getbalance(self):
      return self.balance

Gebruik:
a = Account(1000.00)
a.deposit(550.23)
a.deposit(100)
a.withdraw(50)
print a.getbalance()

Add A Comment

You must be logged in to post a comment.

Home | info@eecho.info | Voorwaarden | Blog