0
thing = 'window'

if 'table' or 'chair' in thing.lower().split():
        print('AHHHHHH I HATE THIS SO MUCH')

For some reason the statement is printed, even though 'table' or 'chair' are clearly not in the variable. Why does this happen?

Wiiat
  • 1
  • 3
  • Basically same thing as [this](https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true) and [this](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values). – ForceBru May 13 '21 at 19:54
  • because `'table' or 'chair' in thing.lower().split()` is always true, it. is equivalent to `('table') or ('chair' in thing.lower().split())` so regardless of what happens with `'chair' in thing.lower().split())`, `'table'` always evaluates to true since it is a non-empty string – juanpa.arrivillaga May 13 '21 at 19:59

0 Answers0