Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

Operator +=

Extends the list on the left with the elements of the iterable on the right.

Version: Python 3.14; repository image, production runtime not attested

Syntax

target += value

Extends the list on the left with the elements of the iterable on the right.

For numeric operands, augmented addition computes a new value for the target. For a mutable list, it extends the existing list with elements from the iterable on the right.

The target is evaluated once. If in-place addition is unavailable, Python tries ordinary addition and assigns its result; code must not assume that object identity is preserved.

Augmented addition can extend a list in place. Existing aliases observe the added elements.

Syntax

target += value

__iadd__, __add__, __radd__ · TypeError

Worked example

a = [1]; b = a; a += (2, 3)
b → [1, 2, 3]
a is b → True
x = 4; previous = x; x += 3
(x, previous) → (7, 4)

Examples

value = [1, 2]
another = value
value += [3]
print(value)
print(another is value)

Result

[1, 2, 3]
True

Augmented addition can extend a list in place. Existing aliases observe the added elements.

Sources