0
What does this mean ?
If __ne__ is not implemented, it returns the opposite of __eq__
3 Respostas
0
When the original test is "!="
Python prefers the direct answer first:
~ call the function that tests: are these things "not_equal"?
If the direct answer is not available, it will ask the opposite question:
~ call the (other) function that tests: are these things "equal"?
In the second case, Python recognizes that you did not originally ask if they were equal...
...so it flips that answer from True to False (and vice versa)
[meta, warning]
Each function can have different internal tests, an opportunity for bugs.
0
Does python do that automatically?
0
I'm really sorry to do this to you...It appears that the documentation has changed to read differently than the text you have posted.
I found an online argument about Python's behavior that was larger than expected, reading:
Quote:
"BE CAREFUL, in this thread all the other answers are wrong or outdated. See ShadowRanger's answer for the correct implementation and this answer for an explanation. – Maggyero Dec 9 at 23:53"
...here's ShadowRanger's "right behavior" answer:
https://stackoverflow.com/a/35781654
...with Maggyero's explanation and samples, including "the default Python 3 implementation":
https://stackoverflow.com/a/50661674
If you stick to just the one destination my links highlight (then skim for the code examples), I hope it will not be overwhelming.
I'll try to sort this out but wanted you to have a chance to look in the meantime.