Well, one reason is that the assignment operator =
must have an expression on the right, not a (series of) statement(s). You might then ask why this is so, and I guess it is chosen to limit the complexity of the parser, and to disallow what one might consider confusing code.
Note that your toto
can be spelled out in a valid way like so:
toto = (
m
for m in range(5)
if m < 4
)
(line breaks and indentation only there to emphasize that this is very close to the same structure as in your invalid code).
1
solved python generator as expression [closed]