Skip to content

Instantly share code, notes, and snippets.

@vubon
Created September 14, 2019 14:00
Show Gist options
  • Save vubon/e87087176183a9b4092fb2cb7ea4646c to your computer and use it in GitHub Desktop.
Save vubon/e87087176183a9b4092fb2cb7ea4646c to your computer and use it in GitHub Desktop.
Python Property function part 1
class Account:
""" A basic class that store bank account information """
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 __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}")
# Output should look like this
# account number: 0004-0067894712
# Current balance: 1000.5
# Account information: {'bank_account': '0004-0067894712', 'balance': 1000.5}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment