.insert()

christian.dinh's avatar
Published May 5, 2021Updated Sep 3, 2021
Contribute to Docs

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...

All contributors

Contribute to Docs

Learn Python on Codecademy