List Methods

list.extend()

Consumes an iterable and appends its yielded elements to the original list. A string contributes characters and a mapping normally contributes keys. Nested items remain shared. Unlike append(), extend() adds each yielded element separately. A failing iterator can leave a partially extended list; it is not transactional. Avoid iterating a growing list through a live iterator while extending it.

Formal Syntax & Structure

python syntaxpython
items.extend(iterable, /)

Parameters & Attributes

NameTypeDescription
iterableiterableSource of zero or more elements.

Return Value

None

The original list changes; no new list is returned.

Working Example

Example Snippetpython
cart = ["pen"]cart.extend(("book", "bag"))cart.extend(name.upper() for name in ["map", "tag"])print(cart)
Python Reference