Python And Or statements acting ..weird

前端 未结 5 1458
盖世英雄少女心
盖世英雄少女心 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:07

    Your print statement will always happen, because your logic statement is always going to be True.
    if A or B:
    will be True if either A is True OR B is True OR both are True. Because of the way you've written the statement, one of the two will always be True. More precisely, with your statement as written, the if statement correlates to if True or False: which simplifies to if True:.
    It seems that you want an and statement instead of an or.

提交回复
热议问题