-2
我從字面上逐字複製指南。我把這個代碼: 對接:Python中的簡單類錯誤來自指南
class Dog():
def _init_(self, name, age):
self.name = name
self.age = age
def sit(self):
print(self.name.title() + " is now sitting")
def roll_over(self):
print(self.name.title() + " rolled over")
my_dog = Dog('willie', 6)
my_dog.sit()
my_dog.roll_over()
然而,而不是讓「威利已經翻滾」我得到:
Traceback (most recent call last):
File "dog.py", line 10, in <module>
my_dog = Dog('willie', 6)
TypeError: object() takes no parameters
請幫助我....我想知道我做錯了什麼!
'__init__'兩邊都需要兩個下劃線。 –