【发布时间】:2014-09-13 19:38:54
【问题描述】:
在编程方面我是最年轻的,但一直在进步。然而,我的头脑仍然需要完全理解正在发生的事情。
class classname:
def createname(self, name):
self.name = name;
def displayname(self):
return self.name;
def saying(self):
print("Hello %s" % self.name);
first = classname;
second = classname;
first.createname("Bobby");
错误:
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
first.createname("Bobby")
TypeError: createname() missing 1 required positional argument: 'name'
错误告诉我,我需要在名称中再添加 1 个参数,所以我肯定在那里出错了,但我已经尝试过这样的事情:
first.createname("bobby", "timmy");
我也排除了它是def createname(self, name) 的事实,因为self 是或应该是单独的而不包括在内?所以我真的不明白发生了什么。
【问题讨论】:
-
很抱歉,但在 python 中,分号(“;”)从不在行尾使用......(有例外,但这些也是不好的做法)