当前位置: 移动技术网 > IT编程>脚本编程>Python > Python 利用字典实现类似 java switch case 功能

Python 利用字典实现类似 java switch case 功能

2018年05月08日  | 移动技术网IT编程  | 我要评论

pdtcap,作文 我的家,长相守曲谱

def add():
    print('add')

def sub():
    print('sub')

def exit():
    print('exit')

choice = { '1' : add, '2' : sub, '3' : exit}

item = input('please input your number! ')

if item in choice:
    choice[item]()

运行结果:
please input your number! 2
sub

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网