Python_堆栈和队列

堆栈和队列

(1)堆栈,新放进去的先取出

#encoding=utf-8

>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> print (stack)
[3, 4, 5, 6, 7]
>>> print (stack.pop())
7
>>> print (stack)
[3, 4, 5, 6]
>>> print (stack.pop())
6
>>> print (stack.pop())
5
>>> print (stack)
[3, 4]
>>>

 

(2)队列

队列:按顺序取出

()简单应用

s = ["a","b","c","d","e"]

s.pop(0)

print(s)

 

 

posted @ 2018-10-08 18:15  翻滚的小强  阅读(130)  评论(0编辑  收藏  举报