3 ms·
This is addressed in the PEP: https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-existing-assignment-into-an-expression https://www.python.org/dev/peps
by misnome 8y ago
This is addressed in the PEP: https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-existing-assignment-into-an-expression https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-.... Their argument seems to be that 'if a = b()' is too similar to 'if a == b():' and thus doing that would cause more mistakes, whereas at the moment (?) they are caught by the parser.
- AlexandrB 8y agoYes. This mistake is very common in C. So much so that it's considered good practice to put the constant first when doing equality comparisons: if (10 == x) This way accidentally missing a "=" triggers a compiler error instead of quietly doing the wrong thing.
- sorenjan 8y agoCalled Yoda conditions. https://en.wikipedia.org/wiki/Yoda_conditions https://en.wikipedia.org/wiki/Yoda_conditions