【发布时间】:2013-02-23 18:05:55
【问题描述】:
我对此有点生气,尝试使用 Python 3.3.0。
http://docs.python.org/3/tutorial/classes.html 上有一个类示例,代码如下:
class Bag:
def __init__(self):
self.data = []
def add(self, x):
self.data.append(x)
首先我想知道它缺少 Python3 通常需要的对象 class somename(object)。
class Bag(object):
其次,当我尝试运行它时,我收到以下错误消息:
>>> a=Bag
>>> a.add('23')
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
a.add('23')
TypeError: add() missing 1 required positional argument: 'x'
WTF?
【问题讨论】:
标签: python class python-3.3