父类的初始化参数
class BankAccount:
def __init__(self,name,account,balance):
self.name = name
self.account = account
self.balance = float(balance)
子类初始化参数
class IterestAccount(BankAccount):
def __init__(self,rate):
BankAccount.__init__(self)
self.rate = rate
令BalanceInYears = IterestAccount('ye','zhanghu',50,0.05)时
出现错误
BalanceInYears = IterestAccount('ye','zhanghu',50,0.05)
TypeError: __init__() takes exactly 2 arguments (5 given)
改成 BalanceInYears = IterestAccount(0.05)
出现
BankAccount.__init__(self)
TypeError: __init__() takes exactly 4 arguments (1 given)
心好累啊 |
|
|
|
|
共 1 个关于本帖的回复 最后回复于 2016-9-7 10:39