+ 1
Weird Python Weirdness
I made a code demonstrating and explaining the problem here: https://code.sololearn.com/c0BU1ctxAZG4/?ref=app
4 Answers
+ 10
I believe 1 == "hj" in "ahj" is internally changed to 1 == "hj" and "hj" in "ahj" which in turn evaluates to False and True which is False. By introducing parentheses, this change isn't done so it creates different results.
+ 7
This is the official docs. Try googling "comparison chaining" or similar if you'd like more info.
https://docs.python.org/3.9/reference/expressions.html#comparisons
+ 1
Russ ah, I see. Thank you.
0
Russ Thatâs interesting. Is there any documentation anywhere on this internal changing?