4 ms·
Can you explain why it doesn't work?
by skrebbel 7y ago
Can you explain why it doesn't work?
- tryptophan 7y agoIt's: if (x in odds} and (odds == expect_odd). The 2nd expression is obviously false always.
- wadkar 7y agoBecause chaining the operator results in: > if x in odds == expect_odd : > if x in odds and odds == expect_odd : with the latter always evaluating to False (assuming expect_odd is a boolean flag).
- weare138 7y agoI'm not a Python expert so I don't know much about the internals of Python but my hunch is when Python evaluates 'x in odds' it's not storing that value internally as a boolean so when you use the '==' strict comparison Python is expecting both data types to be the same.