Python List Insert Method


title: List Insert Method

List Insert Method

The method insert(i,x) inserts a given value x into the list at index i. The index must be within the bounds of the list
(from 0 to the length of the list minus 1).

Example Usage

numbers = [1, 2, 3, 4, 5] numbers.insert(3,8) print(numbers)

Output

[1, 2, 3, 8, 4, 5]

The value 8 is inserted into the list at position 3.

More Information:

This article needs improvement. You can help improve this article. You can also write similar articles and help the community.