![](/img/trans.png)
[英]why am i getting "AttributeError: 'NoneType' object has no attribute 'get' "
[英]Why am I getting 'NoneType' object has no attribute 'beep'?
class Vehicle():
def __init__(self,price,color,gas):
self.price = price
self.gas = gas
self.color = color
def hello(self):
print('hi how are you?')
def fillUpTank(self):
self.gas = 100
def emptyTank(self):
self.gas = 0
def gasLeft(self):
return self.gas
def Car(Vehicle):
def __init__(self,price,color,gas,speed):
super.__init__(self,price,color,gas)
self.speed = speed
def beep(self):
print('Beep Beep!')
def hello(self):
print('beep!')
jim = Vehicle(200,'blue','petrol'`
jim.hello()
tim = Car(500)
tim.beep()
當我嘗試運行 jim.hello() 時,它沒有顯示任何錯誤,但是當我嘗試運行 tim.beep() 時
請在Car
class not def
之前使用class
關鍵字。 實際上,您將Car
定義為 function,請使用class
關鍵字將其定義為 class。
class Car(Vehicle):
def __init__(self,price,color,gas,speed):
super.__init__(self,price,color,gas)
self.speed = speed
def beep(self):
print('Beep Beep!')
def hello(self):
print('beep!')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.