This line doesn't do what you think it does. It is parsed like this:
if ('test' == 'nada') or 'nothing':
print('ok')
else:
print('nope')
Which will always execute, because even though 'test' != 'nada', 'nothing' is truthy because of bool(non-empty-str). It's the same as if False or True:.
The better way would be:
if 'test' in ('nada', 'nothing'):
print('ok')
I rewrote this for Python 3, using a dict-style instead of if-else, and reformatted the output.
This line doesn't do what you think it does. It is parsed like this:
Which will always execute, because even though
'test' != 'nada','nothing'is truthy because ofbool(non-empty-str). It's the same asif False or True:.The better way would be:
I rewrote this for Python 3, using a
dict-style instead ofif-else, and reformatted the output.