目标:
1.编写菜单,提示用户操作选项(push,pop,view,quit)
2.规则:定义列表,先入栈,后出栈,后入栈,先出栈
1.模拟入栈、出栈操作
>>> list1 = [] >>> list1.append('a') >>> list1 ['a'] >>> list1.append('b') >>> list1 ['a', 'b'] >>> list1.pop() 'b' >>> list1 ['a'] >>> list1.pop() 'a' >>> list1 [] >>>
2.编写实现模拟入栈、出栈以及查询等功能
[root@localhost python]# cat in_stack_out.py #!/usr/bin/env python #coding:utf8 db = []
#定义入栈函数 def push_it(): item = raw_input("item: ") db.append(item)
#定义出栈函数 def pop_it(): if db: print "Poped item is:", db.pop() else: print "