Yes, override the __iadd__
method. Example:
def __iadd__(self, other):
self.number += other.number
return self
More Related Contents:
- Python: Does Python have a ternary conditional operator?
- Why “cat” is not equal to “dog” in Python [duplicate]
- Does Python have a ternary conditional operator?
- Understanding the “is” operator
- What is the result of % in Python?
- When is “i += x” different from “i = i + x” in Python?
- The tilde operator in Python
- Asterisk in function call [duplicate]
- proper name for python * operator?
- What does the percentage sign mean in Python
- What does % do to strings in Python?
- ‘is’ operator behaves differently when comparing strings with spaces
- Is there a “not equal” operator in Python?
- Why are there no ++ and – operators in Python?
- What is the difference between i = i + 1 and i += 1 in a ‘for’ loop? [duplicate]
- “x not in” vs. “not x in” [duplicate]
- Python: multiplication override
- Python unpacking operator (*)
- Overriding properties in python
- Should __ne__ be implemented as the negation of __eq__?
- Override the {…} notation so i get an OrderedDict() instead of a dict()?
- What is the difference between ‘+=’ and ‘=+’? [duplicate]
- In Python, how do I indicate I’m overriding a method?
- >> operator in Python
- Python Class __div__ issue
- Is there a short-hand for nth root of x in Python?
- What does the ** maths operator do in Python?
- Force child class to override parent’s methods
- How does Python implement the modulo operation?
- How do I get a decimal value when using the division operator in Python?