Python List insert() method
Description
The insert() function inserts a specified object at a specified position in a list.
Syntax
insert() method syntax:
list.insert(index, obj)
Parameters
- index -- the index position at which object obj should be inserted.
- obj -- the object to insert into the list.
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
)
"
Final List :
"
,
aList
The output of the above example is:
Final List : [123, 'xyz', 'zara', 2009, 'abc']
Python Lists