簡體   English   中英

Python從子方法調用父方法

[英]Python Call Parent Method from child method

我想調用方法SavingsAccount.withdraw(600)但是每次我遇到異常TypeError: withdraw takes exactly 1 arguement(2 given) 我該如何解決? 請指教。

class BankAccount(object):
    def __init__(self):
        pass

    def withdraw(self):
        pass

    def deposit(self):
        pass


class SavingsAccount(BankAccount):
    def __init__(self):
        self.balance = 500

    def deposit(self, amount):
        if (amount < 0):
            return "Invalid deposit amount"
        else:
            self.balance += amount
            return self.balance

    def withdraw(self, amount):
        if ((self.balance - amount) > 0) and ((self.balance - amount) < 500):
            return "Cannot withdraw beyond the minimum account balance"
        elif (self.balance - amount) < 0:
            return "Cannot withdraw beyond the current account balance"
        elif amount < 0:
            return "Invalid withdraw amount"
        else:
            self.balance -= amount
            return self.balance


class CurrentAccount(BankAccount):
    def __init__(self, balance=0):
        super(CurrentAccount, self).__init__()

    def deposit(self, amount):
        return super(CurrentAccount, self).deposit(amount)

    def withdraw(self, amount):
        return super(CurrentAccount, self).withdraw(amount)


x = CurrentAccount();

print  x.withdraw(600)

BankAccountwithdraw方法缺少該金額:

class BankAccount(object):
    def __init__(self):
        pass

    def withdraw(self):   # <--- ADD THE AMOUNT HERE
        pass

deposit方式相同

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM