Advertisement

Python3学习笔记:实现多项选择菜单

阅读量:

Python语言本身并未提供switch - case结构,因此在需要处理多分支选择时,通常采用if - elif语句来完成相应逻辑。
在Python中,可以采取如下方式实现:

复制代码
    def f1():
    dosomething
    .
    .
    .
    def fn():
    dosomething
    
    fun_list = [f1, ... fn]
    ch = input(‘input 0 -  9  :’)
    ch = int(ch)
    f = fun_list[ch]
    f()
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

全部评论 (0)

还没有任何评论哟~