[Python-Dev] assignment expressions: an alternative proposal
MRAB
python at mrabarnett.plus.com
Tue Apr 24 21:01:02 EDT 2018
On 2018-04-24 23:32, Cameron Simpson wrote:
> On 24Apr2018 08:51, Ethan Furman <ethan at stoneleaf.us> wrote:
>>>When I compare to variables from outer scopes they *usually* are on
>>>the *right* side of '=='.
>>
>>You mean something like
>>
>> if 2 == x:
>>
>>? I never write code like that, and I haven't seen it, either.
>
> Just to this, I also never write code like that but I've certainly seen it
> advocated.
>
> I think the rationale was that it places the comparison value foremost in one's
> mind, versus the name being tested. I'm not persuaded, but it is another
> subjective situation.
>
It's sometimes advocated in C/C++ code to help catch the inadvertent use
of = instead of ==, but that's not a problem in Python.
More information about the Python-Dev
mailing list