请教关于Learning Python这本书一个例子上出现的问题

2011-03-20 22:04:09 +08:00
 walkingway
本人菜鸟一只,最近在看Learning Python这本入门书,书上的例子基本都会敲一遍,在看到第四章最后那个用户自定义类那里(大概105页),有个例子敲进去总提示:构造函数没有参数。请教一下各位大牛。


>>> class Worker:
def _init_(self,name,pay):
self.name=name
self.pay=pay
def lastName(self):
return self.name.split()[-1]
def giveRaise(self,percent):
self.pay*=(1.0+percent)
这里构造完以后输入下面的第一条语句就出现错误了
>>>bob=worker('Bob Smith',50000)

具体错误
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
bob=Worker('Bob smith',50000)
TypeError: this constructor takes no arguments

我用的是IDLE 2.7版本的python
4877 次点击
所在节点    Python
2 条回复
darcy
2011-03-20 22:12:34 +08:00
def _init_(self,name,pay):
>>
def __init__(self,name,pay):
walkingway
2011-03-20 22:34:01 +08:00
@darcy 啊,我也发现了,多谢了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/10111

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX