list.insert() Insert at index
Last updated: 2026-09-22
list.insert() Insert at index
list.insert(i, x) inserts x at index i (clamped to start or end).
| Category | List Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
list.insert(i, x)
⚙️ Parameters
| i Required | Index at which to insert; out-of-range is clamped to either end. |
|---|---|
| x Required | The element to insert. |
Returns:None (inserts x at index i in place).
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
[1, 2, 3]
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does insert(0, x) do?
AIt inserts x at the head of the list, equivalent to a prepend.
QWhat happens when the index is out of range?
ANo error; it is automatically placed at either end: insert(100, x) appends at the end, insert(-100, x) inserts at the head.
QWhat does insert() return?
ANone; it modifies in place.