[Python-ideas] Reverse assignment operators (=+, =-, =*, =/, =//, =**, =%)
João Matos
jcrmatos at gmail.com
Sat Nov 12 15:08:00 EST 2016
Hello,
I would like to propose some reversed assignment operators.
Python already has some assignment operators:
a += c is the same as a = a + c
a -= c is the same as a = a - c
a *= c is the same as a = a * c
a /= c is the same as a = a / c
a //= c is the same as a = a // c
a %= c is the same as a = a % c
a **= c is the same as a = a ** c
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
For addition (+= and =+), multiplication (*= and =*) and subtraction (-=
and =-) of numbers it would give the same result, but addition (+= and
=+) and multiplication (*= and =*) when used with strings return a
different result.
All the other operations (=/, =%, =** and =//) return a different result.
I think it is simple and easy to understand, therefore pythonic. :)
Best regards,
JM
More information about the Python-ideas
mailing list