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(sel

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 06:02:02
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(sel

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(sel
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 '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(sel
_init_(self):
这句,你只打了1个下划线.在init两边要各打2个下划线
__init__这样