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[“show”] contains either of these strings, then assign some value to self.xx
But is this “IF” command is correct? Because from my results, it seems like this if command is always true(which is impossible)
Try the following:
Your current if statement will always evaluate to
True, because instead of checking if each string is inattrs["show"]you are checking if"aa"is True, or if"bb"is True, and on and on. Since"aa"will always evaluate as True in a Boolean context, you will always enter theifclause.Instead, use the
any()function as in my example, which accepts an iterable and returns True if any of its elements are True. Similar to a bunch ofor‘s as in your code, this will short-circuit as soon as it finds an element that is True. In this example, the above code is equivalent to the following (but much more concise!):