if command in python

前端 未结 3 1702
灰色年华
灰色年华 2021-01-20 18:03
if \"aa\" or \"bb\" or \"cc\" or \"dd\" or \"ee\" or \"ff\" in attrs[\"show\"]:
    self.xx = xxxx

I have a code like this, to check if attrs[\"sho

3条回答
  •  我在风中等你
    2021-01-20 18:32

    Your IF statement is not testing for anything. It WILL always evaluate as true, because of the way it is written.

    You are asking python:

    Is aa true
    Is bb true
    ...
    

    Python says 'Yes, "aa" is true, because its there!'

    Correct your if statement or find a better way to find the values in the list:

    any(x in ['aa','bb','cc','dd','ee','ff'] for x in attrs["show"])
    

提交回复
热议问题