Understanding condition logic

后端 未结 2 593
一个人的身影
一个人的身影 2021-01-25 05:17

I\'m writing a python program that takes a given sentence in plan English and extracts some commands from it. It\'s very simple right now, but I was getting some unexpected resu

2条回答
  •  旧时难觅i
    2021-01-25 05:44

    "workspace" or "screen" or "desktop" or "switch" is an expression, which always evaluate to "workspace".

    Python's object has truth value. 0, False, [] and '' are false, for example. the result of an or expression is the first expression that evaluates to true. "workspace" is "true" in this sense: it is not the empty string.

    you probably meant:

    "workspace" in command or "screen" in command or "desktop" in command or "switch" in command
    

    which is a verbose way to say what @Ashwini Chaudhary has used any for.

提交回复
热议问题