Python Equality Check Difference

后端 未结 4 897
甜味超标
甜味超标 2021-02-05 00:37

Suppose we want some block of code to be executed when both \'a\' and \'b\' are equal to say 5. Then we can write like :

if a == 5 and b == 5:
    # do something         


        
4条回答
  •  我寻月下人不归
    2021-02-05 01:07

    If you have more variables to test, using all might be slightly more readable:

    if all(i==5 for i in [a,b,c,d]):
        # do something
    

提交回复
热议问题