List Methods

list.insert()

Inserts a single object before the position specified by index. Negative positions are relative to the end; very small positions insert at the beginning, and ordinary positions beyond the end append. CPython must shift later references for insertion near the front, so repeated front insertions are usually inefficient. Prefer append() for adding at the end. Extremely large integers outside CPython’s index range can raise OverflowError.

Formal Syntax & Structure

python syntaxpython
items.insert(index, value, /)

Parameters & Attributes

NameTypeDescription
indexinteger-likeInsertion position; accepts objects implementing the integer index protocol.
valueobjectObject to add or search for.

Return Value

None

The original list changes; no new list is returned.

Working Example

Example Snippetpython
queue = ["review", "publish"]queue.insert(0, "draft")queue.insert(-1, "approve")queue.insert(99, "archive")print(queue)
Python Reference