我看过类似的问题,但仍然无法弄清楚这一点。我绝对相信我在某个地方犯了一个非常愚蠢的错误,但我似乎无法找到它。混淆为什么我得到一个TypeError:'int'对象不可调用
对于此代码。
class BankAccount:
def __init__(self, initial_balance):
self.balance = initial_balance
def deposit(self, amount):
self.deposit = amount
self.balance = self.balance + self.deposit
def withdraw(self, amount):
self.withdraw = amount
self.balance = self.balance - self.withdraw
self.fee = 5
self.total_fees = 0
if self.balance < 0:
self.balance = self.balance - self.fee
self.total_fees += self.fee
def get_balance(self):
current_balance = self.balance
return current_balance
def get_fees(self):
return self.total_fees
当我运行代码的一切工作正常,当我运行这个
my_account = BankAccount(10)
my_account.withdraw(15)
my_account.deposit(20)
print my_account.get_balance(), my_account.get_fees()
但是,如果我做一个额外的呼叫撤回
my_account = BankAccount(10)
my_account.withdraw(15)
my_account.withdraw(15)
my_account.deposit(20)
print my_account.get_balance(), my_account.get_fees()
它抛出这个错误。
TypeError: 'int' object is not callable
我不明白为什么它能正常工作,直到我再打一个电话才能退出。请帮忙。