I notice a strange behavior of "in" operation when comparing a string with a tuple containing only 1 string.
'monday' in ('not monday')
the result is True
as if we were comparing 2 strings
but if I change the expression by adding another element in the tuple.
'monday' in ('not monday', 'not monday neither')
it returns False as expected.
any idea why?
>Solution :
>>> 'monday' in ('not monday')
True
>>> 'monday' in ('not monday',)
False
A single-element tuple must have the trailing comma. Otherwise, it gets interpreted as regular order-of-operations parentheses, which are meaningless in this case So, 'monday' in ('not monday') is syntatically identical to 'monday' in 'not monday'.