Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

list.extend

Adds successive members from an iterable to the end of a list.

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

Syntax

a.extend(iterable)

Adds successive members from an iterable to the end of a list.

A string contributes each character separately. The method returns None after modifying the receiver.

Consumes each input element and appends it to the receiver. The string ab contributes two characters, leaving x, a and b as separate list items. The mutation returns None; a one-pass input iterator is consumed.

a = [0]
assert a.extend(iter([1, 2])) is None and a == [0, 1, 2]

Examples

a = ["x"]
print(a.extend("ab"))
print(a)

Result

None
['x', 'a', 'b']

Consumes each input element and appends it to the receiver. The string ab contributes two characters, leaving x, a and b as separate list items. The mutation returns None; a one-pass input iterator is consumed.

Sources