What does this mean ? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

What does this mean ?

If __ne__ is not implemented, it returns the opposite of __eq__

25th Dec 2018, 1:29 AM
Razf
Razf - avatar
3 Respuestas
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.
25th Dec 2018, 2:16 AM
Kirk Schafer
Kirk Schafer - avatar
0
Does python do that automatically?
25th Dec 2018, 2:39 AM
Razf
Razf - avatar
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.
25th Dec 2018, 3:09 AM
Kirk Schafer
Kirk Schafer - avatar