擅长:python、mysql、java
<p>在你的代码中,你正在做:</p>
<pre><code>species.set_bird(Bird("Red"))
</code></pre>
<p>创建<code>Bird</code>的对象时,传递的是参数<code>"Red"</code>。但是<code>Bird</code>类中没有接受此参数的<code>__init__()</code>函数。您的<code>Bird</code>类应该如下:</p>
<pre><code>class Bird:
# _type = "" <--- Not needed
# Probably you miss understood it with the
# part needed in `__init__()`
def __init__(self, type):
self._type = type
def bird(self, type):
self._type = type
def display(self):
print(self._type)
</code></pre>