Operators

+= — Addition assignment

Increase numeric values or extend supported sequences. A list extends in place and accepts an iterable, whereas integer addition rebinds the target. An immutable tuple can contain a list that is extended before tuple item reassignment raises TypeError. The __iadd__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.

Formal Syntax & Structure

python syntaxpython
target += expression

Parameters & Attributes

NameTypeDescription
targetobjectExisting assignable name, attribute, item or slice; its current value participates in the operation.
rightnumber or supported iterableValue used as the right operand of the operation.

Working Example

Example Snippetpython
count = 7count += 3items = ["pen"]alias = itemsitems += ("book", "bag")print(count)print(alias)print(items is alias)
Python Reference