welcom ! Handel home

2016年5月9日 星期一

python use dict function run ( by switch case example code )

# coding=utf-8

def key1(ss):
    print ("\n run %s ok !" % ss)
    pass
         
def key2(ss):
    print ("\n run %s ok !" % ss)
    pass
           
def key3(ss):
    print ("\n run %s ok !" % ss)
    pass
 
def key4(ss):
    print ("\n run %s ok !" % ss)
    pass

caseloop = {
    "k1":key1,
    "k2":key2,
    "k3":key3,
    "k4":key4
 }    
     
if __name__ == '__main__':
    while 1:
        kk = input("\n type key:")
        caseloop[kk](kk)

沒有留言: