|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class Bird(object):
def __init__(self, name):
self.name=name
def greet(self):
print("Hello, I am %s" % self.name)
class HungryBird(Bird):
def __init__(self):
super(HungryBird, self).__init__()
self.hungry=True
def eat(self):
if self.hungry:
print ("Aaaah")
self.hungry=False
else:
print ("I am full")
代码如上,在实例化HungryBird的时候,总反馈我输入的参数数量不对,晕死!
>>> hb=HungryBird("wuya")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:/Users/Administrator/Desktop/temp2.py", line 13, in __init__
super(HungryBird, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
>>>
>>> hb=HungryBird()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:/Users/Administrator/Desktop/temp2.py", line 13, in __init__
super(HungryBird, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
快晕死了,求救啊!
本帖最后由 凌九霄 于 2018-6-26 20:56 编辑
- class Bird(object):
- def __init__(self, name):
- self.name = name
- def greet(self):
- print("Hello, I am %s" % self.name)
- class HungryBird(Bird):
- def __init__(self,name): #<---
- super(HungryBird, self).__init__(name)
- self.hungry = True
- def eat(self):
- if self.hungry:
- print("Aaaah")
- self.hungry = False
- else:
- print("I am full")
复制代码
|
|