Home > Mobile >  Python OOP, how to keep adding a number Instance attribute?
Python OOP, how to keep adding a number Instance attribute?

Time:11-23

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)

CodePudding user response:

You're reassigning your deposit function to an integer in the line. self.deposit = deposit. Remove that :)

  • Related