21. What will be the output of the following code:
my_list = [1, 2, 3]
my_list[1] = 4
print(my_list)
my_list = [1, 2, 3]
my_list[1] = 4
print(my_list)
22. What is the output of the following code:
my_list = [1, 2, 3, 4, 5]
print(my_list[1:4])
my_list = [1, 2, 3, 4, 5]
print(my_list[1:4])
23. What is the output of the following code:
my_list = [1, 2, 3]
my_list.append(4)
print(my_list)
my_list = [1, 2, 3]
my_list.append(4)
print(my_list)
24. What is the output of the following code:
my_list = [1, 2, 3, 4]
my_list.remove(2)
print(my_list)
my_list = [1, 2, 3, 4]
my_list.remove(2)
print(my_list)
25. What will the following code output:
my_list = [1, 2, 3]
new_list = my_list.copy()
print(new_list)
my_list = [1, 2, 3]
new_list = my_list.copy()
print(new_list)
26. What is the output of the following code:
my_list = [1, 2, 3]
del my_list[1]
print(my_list)
my_list = [1, 2, 3]
del my_list[1]
print(my_list)
27. Which method is used to sort the elements of a list in ascending order?
28. What is the purpose of the reverse() method for lists?
29. What will be the output of the following code:
my_list = [1, 2, 3]
my_list.reverse()
print(my_list)
my_list = [1, 2, 3]
my_list.reverse()
print(my_list)
30. What is the output of the following code:
my_list = [1, 2, 3, 4]
my_list.pop()
print(my_list)
my_list = [1, 2, 3, 4]
my_list.pop()
print(my_list)
Read More Section(Lists in Python)
Each Section contains maximum 100 MCQs question on Lists in Python. To get more questions visit other sections.