Skip to content

Instantly share code, notes, and snippets.

@vubon
Created September 14, 2019 14:06
Show Gist options
  • Save vubon/c5a9c4f60d1c2c81a44fdfd6bd95113d to your computer and use it in GitHub Desktop.
Save vubon/c5a9c4f60d1c2c81a44fdfd6bd95113d to your computer and use it in GitHub Desktop.
Python Property function part 3
class Account:
""" A basic account information store class """
def __init__(self, bank_account: str, balance: float):
self.bank_account = bank_account
self.balance = balance
# self.account_information = dict(bank_account=self.bank_account, balance=self.balance)
def account_information(self) -> dict:
"""
Get account information
:return: {'bank_account': '0004-0067894712', 'balance': 1000.5}
:rtype: dict
"""
return dict(bank_account=self.bank_account, balance=self.balance)
def __str__(self):
return f"Bank Account: {self.bank_account} - balance: {self.balance}"
account = Account("0004-0067894712", 1000.50)
print(f"account number: {account.bank_account}")
print(f"Current balance: {account.balance}")
print(f"Account information: {account.account_information()}")
# Fund transfer process
account.balance = account.balance - 500.25
# Now call the account_information attribute
print("Calling the account_information attribute")
print(f"Account information: {account.account_information()}")
print(f"Current balance: {account.balance}")
#Output
"""
account number: 0004-0067894712
Current balance: 1000.5
Account information: {'bank_account': '0004-0067894712', 'balance': 1000.5}
Calling the account_information attribute
Account information: {'bank_account': '0004-0067894712', 'balance': 500.25}
Current balance: 500.25
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment