Trying to deposit into the wallet, it worked the first call, then when I call the deposit function again it would give me the error.
TypeError: 'int' object is not callable
Any solutions to this?
class Bank():
def __init__(self,wallet):
self.wallet = wallet
def withdraw(self,withdraw):
self.withdraw = withdraw
def deposit(self, deposit):
self.deposit = deposit
self.wallet += self.deposit
bank = Bank(0)
bank.deposit(500)
print(bank.wallet)
bank.deposit(500)
print(bank.wallet)
self.deposit = deposit? Once you've done thatbank.depositis not a method any more, it's an int.__init__methods frequently because__init__is where you define all the attributes of an object, but you usually don't want to set new attributes outside of__init__, nor do all the attributes set in__init__need to be 1:1 with the function arguments. For example, yourBank.__init__could just always setself.wallet = 0to start with and not require awalletargument at all.