作业帮 > 综合 > 作业

python AttributeError: 'Stack' object has no attribute 'stac

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/10/07 02:26:06
python AttributeError: 'Stack' object has no attribute 'stack'
class Stack(object):
def _init_(self):
self.stack=[]
def push(self,object):
self.stack.append(object)
def pop(self):
return self.stack.pop()
def length(self):
return len(self,stack)


s=Stack()
s.push("Dave")
s.push(42)
s.push([3,4,5])
x=s.pop()
y=s.pop()
print x,y


运行是报错,这是python精要上面的例子.报错的内容是AttributeError: 'Stack' object has no attribute 'stack'
python AttributeError: 'Stack' object has no attribute 'stac
_init_(self):
这句,你只打了1个下划线.在init两边要各打2个下划线
__init__这样