[Python-ideas] Reverse assignment operators (=+, =-, =*, =/, =//, =**, =%)

Todd toddrjen at gmail.com
Sun Nov 13 18:08:22 EST 2016


On Sun, Nov 13, 2016 at 4:00 PM, Mikhail V <mikhailwas at gmail.com> wrote:

> On 12 November 2016 at 21:08, João Matos <jcrmatos at gmail.com> wrote:
>
> > What I would like to propose is the creation of the reverse:
> > a =+ c is the same as a = c + a
> > a =- c is the same as a = c - a
> > a =* c is the same as a = c * a
> > a =/ c is the same as a = c / a
> > a =// c is the same as a = c // a
> > a =% c is the same as a = c % a
> > a =** c is the same as a = c ** a
>
> A good syntax example:
>
> a = sum (a, c)
> a = mul (a, c)
> a = div (a, c)
>

Except that there is no "div" in python 3.x, and "sum(a, c)" does not add
"a" and "c".


> Another good syntax, I'm not a fan of, but at least intuitive and
> learnt in school:
>
> a = a + c
> a = a * c
> a = a / c
>

How is using a function better than using an operator?  Especially
considering the ambiguity issues you just demonstrated.

The fact the operator version is part of the core language while the
function versions aren't even builtins (they are in the "operator" module)
suggests to me that the function version is not the preferred version in
Python.


> Bad syntax, not readable:
>
> a += c
> a -= c
> a *= c
>
>
What, specifically, is not readable about this syntax?


> As for me, I would even prohibit all these +=  for the sake of readability.
>

Great, so I will have to make a copy of my 500 MB array every time I want
to do a simple mathematical operation on it rather than being able to do
the operation in-place.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161113/673ffe26/attachment.html>


More information about the Python-ideas mailing list