.insert()

Adds an item at a specified index in the list.

Syntax

list.insert(index, item)

The .insert() method takes in two parameters:

  • The index that you want to insert into.
  • The item that you want to insert at the specified index.

Example

To add an item at index 2 of store_line list:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy

Contributors