python的list的pop()问题
- Python code
class Stack(object): def __init__(self): self.stack=[] def push(self,object): self.stack.append(object) def pop(self): self.stack.pop() def length(self): return len(self.stack)s=Stack()s.push("Dave")s.push(42)s.push([3,4,5])print s.length()print s.pop()y=s.pop()print ydel s
F:\python>stack.py
3
None
None
为什么pop()没有值呢?
print s.pop()
y=s.pop()
print y
初学python,谢谢解答。
[解决办法]
lz 都没有返回值,又哪来的值呢
- Python code
class Stack(object): def __init__(self): self.stack=[] def push(self,object): return self.stack.append(object) def pop(self): return self.stack.pop() def length(self): return len(self.stack