![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What do the =+ and += do in Python?
The += operator is syntactic sugar for object.__iadd__() function. From the python docs:
These methods are called to implement the augmented arithmetic assignments (+=, -=, *=, @=, /=, //=, %=, **=, <<=, >>=, &=, ^=, |=). These methods should attempt to do the operation in-place (modifying self) and return the result (which could be, but does not have to be, self).
Example
So when you do something like −
a = 5 b = 10 a += b print(a)
Output
This will give the output −
15
a is being modified in place here. You can read more about such operators on https://docs.python.org/3/reference/datamodel.html#object.__iadd__.
The =+ operator is the same as if you were to do something like a = -b, except positive instead of negative. It basically is the same as a = b though, as adding a '+' before a value does not change it. This is called a unary operator as there is only one argument (ex: +a) instead of two (ex: a+b).