博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
47-使用列表进行模拟栈
阅读量:7240 次
发布时间:2019-06-29

本文共 630 字,大约阅读时间需要 2 分钟。

stack = []def push_it(): item = input('item to push: ') stack.append(item) def pop_it(): if stack: print("from stack popped %s" % stack.pop()) def view_it(): print(stack) def show_menu(): cmds = { '0': push_it, '1': pop_it, '2': view_it} # 将函数存入字典 prompt = """(0) push it (1) pop it (2) view it (3) exit Please input your choice(0/1/2/3): """ while True: # input()得到字符串,用strip()去除两端空白,再取下标为0的字符 choice = input(prompt).strip()[0] if choice not in '0123': print('Invalid input. Try again.') continue if choice == '3': break cmds[choice]() if __name__ == '__main__': show_menu()

转载于:https://www.cnblogs.com/hejianping/p/10907180.html

你可能感兴趣的文章
Hibernate中createCriteria即QBC查询的详细用法
查看>>
《ArcGIS Runtime SDK for Android开发笔记》——(2)、Android Studio基本配置与使用
查看>>
怎么运行 ASP.NET Core控制台程序
查看>>
iOS -Swift 3.0 -UILabel属性大全
查看>>
Convolution1D与Convolution2D区别
查看>>
如何安装Tomcat
查看>>
IOS蓝牙项目总结
查看>>
django一对多 增 删 改 查
查看>>
Sqoop Export原理和详细流程讲解
查看>>
如何实现超高并发的无锁缓存?
查看>>
浅谈对java中锁的理解
查看>>
ASP.NET Core MVC之ViewComponents(视图组件)知多少?
查看>>
在天河二号上对比Julia,Python和R语言
查看>>
Docker容器学习梳理--私有仓库Registry使用
查看>>
arcgis地图服务之 identify 服务
查看>>
取汉子拼音首字母的C#方法
查看>>
C语言 · 求先序遍历
查看>>
java oracle thin 和 oci 连接方式实现多数据库的故障切换
查看>>
使用spring利用HandlerExceptionResolver实现全局异常捕获
查看>>
字符串 上
查看>>