首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python的list的pop()有关问题

2012-04-10 
python的list的pop()问题Python codeclass Stack(object):def __init__(self):self.stack[]def push(self

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 

热点排行