seeking deeper (language theory) reason behind Python design choice
Chris Angelico
rosuav at gmail.com
Wed May 9 01:09:18 EDT 2018
On Wed, May 9, 2018 at 1:48 PM, Python <python at bladeshadow.org> wrote:
>> since = in a statement on its own is not dangerous. People *almost never*
>> intend to write == for the side-effects only:
>
> Seriously? I do this--not every day, but more than occasionally, not
> just in Python.
>
> flag = (spam == arg)
> vs.
> if spam == arg:
> flag = True
> else:
> flag = False
> if flag:
> do_something()
> else:
> do_something_else()
That's not "side effects only". You're evaluating a comparison for its
result - its primary effect. You're assigning the result of the
comparison to something.
Using equality comparisons for side effects would look like this:
spam == arg
No assignment. Just that, as a statement all on its own. It's
perfectly legal, but I doubt you've ever actually done this.
ChrisA
More information about the Python-list
mailing list