Are these equal?
xs[i] == xs[i+1] == xs[i+2]
xs[i] == xs[i+1] and xs[i+1] == xs[i+2]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Python chains such relational operators naturally (including
inandis).a() == b() == c()is functionally equivalent toa() == b() and b() == c()whenever consecutive calls tobreturn the same value and have the same aggregate side effects as a single call tob. For instance, there is no difference between the two expressions wheneverbis a pure function with no side-effects.The easiest way to show the slight difference:
print()always returnsNone, so all we are doing is comparingNones here, so the result is alwaysTrue, but note that in the second case,print(2)is called twice, so we get two2s in the output, while in the first case, the result is used for both comparisons, so it is only executed once.