Python List insert() Method
Example
Insert the value "orange" as the second element of the fruit
list:
fruits = ['apple', 'banana', 'cherry']
fruits.insert(1, "orange")
Run example »
Definition and Usage
The insert()
method inserts the specified value at the specified position.
Syntax
list.insert(pos, elmnt)
Parameter Values
Parameter | Description |
---|---|
pos | Required. A number specifying in which position to insert the value |
elmnt | Required. An element of any type (string, number, object etc.) |