Python: elif or new if?

后端 未结 5 747
谎友^
谎友^ 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:34

    Looking at the code without knowledge of the data then the elif case explicitely states your intentions and is to be preferred.

    The two if statements case would also be harder to maintain as even if comments are added, they would still need to be checked.

提交回复
热议问题