我在這裏看到了一些關於我的錯誤的答案,但它對我沒有幫助。我是一個絕對的noob在Python上的類,並剛剛在9月份開始執行此代碼。反正看看我的代碼TypeError:__init __()只需要3個參數(給出2個參數)
class SimpleCounter():
def __init__(self, startValue, firstValue):
firstValue = startValue
self.count = startValue
def click(self):
self.count += 1
def getCount(self):
return self.count
def __str__(self):
return 'The count is %d ' % (self.count)
def reset(self):
self.count += firstValue
a = SimpleCounter(5)
,這是錯誤我得到
Traceback (most recent call last):
File "C:\Users\Bilal\Downloads\simplecounter.py", line 26, in <module>
a = SimpleCounter(5)
TypeError: __init__() takes exactly 3 arguments (2 given
據透露,你的類應該從'object'繼承(谷歌的蟒蛇新樣式類,如果你是好奇,爲什麼) – ThiefMaster 2012-02-25 14:54:56