Important Python Mcqs

To insert 5 to the third position in list1, we use which command?

a) list1.insert(3, 5)

b) list1.insert(2, 5)

c) list1.add(3, 5)

d) list1.append(3, 5)

Answer:

b) list1.insert(2, 5)

Explanation:

The syntax and working of the insert function in python are shown below:

list1 = [ 1, 2, 3, 4, 5, 6 ]
list1.insert(2, 5) # here 2 is the index, while 5 represents value to be inserted
print(list1)

Output:

[1, 2, 5, 3, 4, 5, 6]

Related MCQs
Aniket Malik

Aniket Malik

CERTIFIED TUTOR/TRAINER WITH 300+ REVIEWS

Facing difficulty with

this concept?