On 29/04/15 21:19, diliup gabadamudalige wrote:

It is partly due to curiosity but I also wanted to have a common update
method. And as I almost always use the x+= some code, y+=some code for
animation stuff I wanted to know how it could be done using this method
rather than finding each position separately and assigning with x= some
code, y = some code (new position).

OK, Curiosity is good.
But the conversion is mainly a math challenge rather than a
programming one. And its a very seductive but dangerous mind
set to try to force a problem into a pattern that fits how
you usually do it. Especially if the transformed code looks
less intuitive than the original.

When I started in Python it didn't even have the += style
of augmented assignment, it was mainly introduced to save
some typing, nothing more.

Remember that += is still an assignment to x. It is not
significantly different or in any way 'better' than
the standard assignment. In languages like C '+='  (and
even more so '++' which doesn't exist in Python) used to
result in performance improvements but optimising
compilers have removed even that reason for using it.
Now it should just be considered a typing shortcut.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to