What does "+=" mean, or do?

30 views
Skip to first unread message

Malik Rumi

unread,
May 12, 2014, 1:22:56 PM5/12/14
to django...@googlegroups.com
I saw it here http://www.slideshare.net/jacobian/the-best-and-worst-of-django on slide 41. That's a lot to go through, I know, sorry about that. But I googled it and of course got nothing because Google ignores things like + and = now. And I know in this particular example he says 'don't do this", I just want to know what += means or does? Thx. 

Tom Evans

unread,
May 12, 2014, 1:26:57 PM5/12/14
to django...@googlegroups.com
+ means addition
= means assignment
+= means addition and assignment

Eg, a += 5 means a = a + 5

Cheers

Tom

PS - the "don't do this" is not about "+="!

Bill Freeman

unread,
May 12, 2014, 1:28:04 PM5/12/14
to django-users
a += b

is nominally the same as

a = a + b

To make class instances support this behavior the class can implement the __iadd__ special method.  See docs.python.org and read about special methods.

This notation originated, so far as I know, in the C language.  It at least goes back that far.


On Mon, May 12, 2014 at 9:22 AM, Malik Rumi <malik....@gmail.com> wrote:
I saw it here http://www.slideshare.net/jacobian/the-best-and-worst-of-django on slide 41. That's a lot to go through, I know, sorry about that. But I googled it and of course got nothing because Google ignores things like + and = now. And I know in this particular example he says 'don't do this", I just want to know what += means or does? Thx. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f364291f-ae62-4b0b-a2d9-23e3f81a64e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Malik Rumi

unread,
May 12, 2014, 1:33:51 PM5/12/14
to django...@googlegroups.com, teva...@googlemail.com
Wow, really quick replies! thanks to both of you!
Reply all
Reply to author
Forward
0 new messages