Python And Or statements acting ..weird

前端 未结 5 1460
盖世英雄少女心
盖世英雄少女心 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 = " "
    

    you have the condition as

    if i != "" or i != " ":
    

    here i != "" will evaluate to True and i != " " will evaluate to False

    so you will have True or False = True

    you can refer this truth table for OR here

    True  or False = True
    False or True  = True
    True  or True  = True
    False or False = False
    

提交回复
热议问题