[Tutor] Why x+=y instead of x=x+y?

Scot W. Stevenson scot@possum.in-berlin.de
Fri, 19 Jul 2002 05:39:32 +0200


Hello Yigal,=20

While reading your post on "Loopy Questions" I noticed these lines:

> =09x +=3D 0.01
>     x +=3D step

Now I know this is shorthand for "x =3D x+0.01" and "x =3D x+step", but I=
 have=20
always wondered what the point is - surely it is not too much to ask for=20
to type that extra character, especially because the resulting version is=
=20
not clear to newbies (why put the "+" _before_ the "=3D", for starters - =
"x=20
=3D+ step" would make more sense). If we want to save space, then "cnt"=20
instead of "continue" or "prt" instead of "print" might be a better place=
=20
to start. =20

Or, to put it differently: Is this just another example of a construct th=
at=20
was included in Python to make the "Waaah, I wanna keep my C style, even=20
if it is bizarre and non-intuitive"-crowd happy, or is there a real=20
difference between "x +=3Dy" and "x =3D x+y" that justifies a notation th=
at=20
looks like a typo?

Y, Scot

--=20
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany