On 3/8/2020 12:07 PM, MRAB wrote:
In Python 3.8+ there's the "walrus operator" which lets you assign
within an expression:
if (first := (color == BLUE and count == 20)) or (second := (color ==
RED and count % 5 == 0)):
rotate_the_wheel()
if first:
set_signal()
if second:
unset_signal()
proc_post_rotate()
However, this has the problem that if the first subexpression is true,
the second will not be evaluated, so 'second' would not be set.
One can use '|' instead of 'or' to force evaluation of the second.
>>> if (first := True) | (second := False):
second
False
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list