Situatie
insert() is an inbuilt function in Python that inserts a given element at a given index in a list.
Syntax: list_name.insert(index, element)
Solutie
Pasi de urmat
list1 = [ 1, 2, 3, 4, 5, 6, 7 ]
list1.insert(4, 10)
print(list1)
list2 = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
list2.insert(0, ‘z’)
print(list2)
Output:
[1, 2, 3, 4, 10, 5, 6, 7]
[‘z’, ‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
Leave A Comment?