Python: elif or new if?

后端 未结 5 714
谎友^
谎友^ 2021-01-04 21:52

What is better to use:

if var in X:
    #do_whatever
elif (var in Y):
    #do_whatever2

or:

if var in X:
    #do_whatever
i         


        
5条回答
  •  悲哀的现实
    2021-01-04 22:37

    If var can't be in both X and Y, then you should use elif. This way, if var in X is true, you don't need to pointlessly eval var in Y.

提交回复
热议问题