more example below:
if (a = xyz() ) > abc:
Really want to know why, is it kinds of bad smell ?
Note: I know the grammar, but I am asking why Python don't support such grammar as many other language( e.g., c , java...) do supporting
more example below:
if (a = xyz() ) > abc:
Really want to know why, is it kinds of bad smell ?
Note: I know the grammar, but I am asking why Python don't support such grammar as many other language( e.g., c , java...) do supporting
From the python design FAQ:
The reason for not allowing assignment in Python expressions is a common, hard-to-find bug in those other languages, caused by this construct:
if (x = 0) { // error handling } else { // code that only works for nonzero x }
The error is a simple typo: x = 0, which assigns 0 to the variable x, was written while the comparison x == 0 is certainly what was intended.
As explained in the FAQ, most "use cases" for using assignment in an expression can be covered by using iterators instead.
Remember python philosophy : There should be one-- and preferably only one --obvious way to do it.
It doesn't sound obvious to me !
Also you may want to check this answer too :
why does python assignment not return a value