Motivation

Motivation#

Using what you know so far, how might you represent a bank account with Python?

You might:

  • use variables to hold the data such as account number, balance and holder name

  • define functions to change those variables as needed

For example

def withdraw(current_balance, withdraw_amount):
    new_balance = current_balance - withdraw_amount
    if new_balance < 0:
        print("WARNING: Account is overdrawn!")
    return new_balance


bsb = "689716"
account_number = "62228626"
balance = 19.39
holder_name = "Bruce Wayne"

Now consider how you might deal with multiple bank accounts. You would need multiples of these variables and you must tediously keep track of which variables belong to which account, even when using sophisticated data structures.

We’ll see that it is much easier to represent something like bank accounts using an object oriented approach.