Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python List insert() method

Python List insert() method

Python Lists Python Lists


Description

The insert() function inserts a specified object at a specified position in a list.

Syntax

insert() method syntax:


list.insert(index, obj)

Parameters

Return Value

This method has no return value, but inserts the object at the specified position in the list.

Example

The following example shows how to use the insert() function:

Example

#!/usr/bin/python

aList

=

[

123

,

'

xyz

'

,

'

zara

'

,

'

abc

'

]

aList

.

insert

(

3

,

2009

)

print

"

Final List :

"

,

aList

The output of the above example is:


Final List : [123, 'xyz', 'zara', 2009, 'abc']

Python Lists Python Lists