擅长:python、mysql、java
<blockquote>
<p>I need to add <code>self.model</code>, <code>self.color</code> and <code>self.mpg</code> to the <code>ElectricCar</code> class.</p>
</blockquote>
<p>Python允许您调用已替换的父类的方法。只需显式调用父类的构造函数。你知道吗</p>
<p><code>ElectricCar.__init__</code>的第一个参数是电池类型。将其余位置参数存储在列表(<code>args</code>)中,并将它们解压到父构造函数:</p>
<pre><code>class ElectricCar(Car):
def __init__(self, battery_type, *args):
super(ElectricCar, self).__init__(*args) # super().__init__(*args) in Py3k+
self.battery_type = battery_type
</code></pre>