- insert() is a python in-build function which is applicable on the list which insert the new item in the list at per the index value.
Syntax-
list.insert(index,item)
- insert() take two argument ,one is index value and another one is item which are to be inserted
Example
list is [1,2,3,4]
add 5 at index 2 will give [1,2,5,3,4]
program-
l=[1,2,3]
print("List is ",l)
l.insert(1,"Insert1")
print("list is ",l)
l.insert(0,"Insert0")
print("list is ",l)
l.insert(3,"Insert3")
print("list is ",l)
l.insert(2,"Insert2")
print("list is ",l)
List is [1, 2, 3]
list is [1, 'Insert1', 2, 3]
list is ['Insert0', 1, 'Insert1', 2, 3]
list is ['Insert0', 1, 'Insert1', 'Insert3', 2, 3]
list is ['Insert0', 1, 'Insert2', 'Insert1', 'Insert3', 2, 3]