【发布时间】:2012-03-15 17:51:07
【问题描述】:
我在这里看到了一些关于我的错误的答案,但这对我没有帮助。我是 Python 课程的绝对菜鸟,并且在 9 月才开始编写此代码。无论如何看看我的代码
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(如果您好奇为什么,请在谷歌上找到 python 新型类)