How to exit an if clause

前端 未结 13 1782
故里飘歌
故里飘歌 2020-12-04 08:45

What sorts of methods exist for prematurely exiting an if clause?

There are times when I\'m writing code and want to put a break statement

13条回答
  •  难免孤独
    2020-12-04 09:09

    The only thing that would apply this without additional methods is elif as the following example

    a = ['yearly', 'monthly', 'quartly', 'semiannual', 'monthly', 'quartly', 'semiannual', 'yearly']
    # start the condition
    if 'monthly' in b: 
        print('monthly') 
    elif 'quartly' in b: 
        print('quartly') 
    elif 'semiannual' in b: 
        print('semiannual') 
    elif 'yearly' in b: 
        print('yearly') 
    else: 
        print('final') 
    

提交回复
热议问题