+ 4
Question from Sololearn's Python Challenge
#1 print("abcded".find("bc") == "cd" in "abcdef") #2 print(1 == True) Output of first print statement is False whereas output of second statement is True. My doubt: When Left side & right side of first statement will evaluate to 1 & True respectively, then why its output is not True. What is the mistake I am doing here?
4 Respuestas
+ 5
It is strange, I also doubled checked it in Termux and I am getting the same result you got, but it works if you put parentheses around each statement, I guess explicit is better than implicit?
print(("abcdef".find("bc")) == ("cd" in "abcdef"))
+ 2
Steven M Does the addition of the brackets change the order in which the statements are executed? I never add brackets for comparison. Thanks for illustrating the possibility for an unnoticed bug to mess with the code here!
+ 2
Calvin Sheen Thomas I assume yes, I took a mathematical approach to it, while also keeping in mind Tim Peters' writing suggestions. Similar coding behavior/style is used in Numpy and Pandas too
0
Steven M That's cool