Python And Or statements acting ..weird

前端 未结 5 1433
盖世英雄少女心
盖世英雄少女心 2020-12-07 04:30

I have this simple line of code:

i = \" \"

if i != \"\" or i != \" \":
    print(\"Something\")

This should be simple, if i is not empty <

5条回答
  •  自闭症患者
    2020-12-07 05:23

    I will explain how or works.
    If checks the first condition and if it is true it does not even check for the second condition.
    If the first condition is false only then it checks for second condition and if it is true the whole thing becomes true.
    Because

    A B Result  
    0 0   0  
    0 1   1  
    1 0   1  
    1 1   1  
    

    So If you want to satisfy both condition of not empty and space use and

提交回复
热议问题