- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 does the &= operator do in Python?
The += operator is syntactic sugar for object.__iand__() 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).
So when you do something like −
a = 6 # 110 in binary b = 5 # 101 in binary a &= b # a changes to and of 110 and 101, ie, 100, ie, 4 print(a)
This will give the output −
a is being modified in place here. You can read more about such operators on https://docs.python.org/3/reference/datamodel.html#object.__iand__.
- What does the >> operator do in Python?
- What does 'in' operator do in Python?
- What does 'is' operator do in Python?
- What does colon ':' operator do in Python?
- What does 'not in' operator do in Python?
- What does the "===" operator do in Kotlin?
- What does 'is not' operator do in Python?
- What does the bitwise left shift operator do in Java?
- What does the bitwise right shift operator do in Java?
- What does the Star operator mean in Python?
- What does "?:" do in Kotlin? (Elvis Operator)
- What does the Double Star operator mean in Python?
- What do the =+ and += do in Python?
- What does % do to strings in Python?