IX_Assignment-5_Ch-4_List_in_Python_-SOLVED[1]
IX_Assignment-5_Ch-4_List_in_Python_-SOLVED[1]
4. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], which of the following is correct syntax for slicing
operation?
a) print(list1[2:]) c) print(list1[:-2])
b) print(list1[:2]) d) all of the mentioned
a) A c) Error
b) Daman d) n
9. Which of the following methods is used to add an element to the end of a list in Python?
a) append() c) insert()
b) add() d) extend()
10. Which of the following methods is used to remove the first occurrence of a specified
element from a list in Python?
a) remove() c) delete()
b) pop() d) discard()
11. What will be the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.pop(2)
print(my_list)
a) [1, 2, 4, 5] c) [1, 2, 4]
b) [1, 2, 3, 5] d) [1, 2, 3, 4]
12. Which of the following methods is used to reverse the elements of a list in Python?
a) reverse() c) swap()
b) sort() d) invert()
13. What is the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.extend([6, 7, 8])
print(my_list)
a) [1, 2, 3, 4, 5, 6, 7, 8] c) [1, 2, 3, 4, 5, (6, 7, 8)]
b) [1, 2, 3, 4, 5, [6, 7, 8]] d) [1, 2, 3, 4, 5, {6, 7, 8}]
14. What will be the output of the following Python code snippet?
my_list = [3, 2, 1, 4, 5]
my_list.sort()
print(my_list)
a) [1, 2, 3, 4, 5] c) [3, 2, 1, 4, 5]
b) [5, 4, 3, 2, 1] d) [1, 3, 2, 4, 5]
15. What is the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.insert(2, 10)
print(my_list)
a) [1, 2, 10, 3, 4, 5] c) [1, 2, 3, 4, 10, 5]
b) [1, 2, 3, 10, 4, 5] d) [1, 2, 3, 4, 5, 10]
16. What will be the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.remove(3)
print(my_list)
a) [1, 2, 4, 5] c) [1, 2, 4]
b) [1, 2, 3, 4] d) [1, 2, 5]
17. What will be the output of the following Python code snippet?
my_list = [1, 2, 3]
new_list = my_list.copy()
my_list.append(4)
print(new_list)
a) [1, 2, 3] c) [1, 2, 3, 4]
b) [1, 2, 3, 4] d) [1, 2, 3, 4]
18. To add a new element to a list we use which command?
a) list1.add(5) c) list1.addLast(5)
b) list1.append(5) d) list1.addEnd(5)
a) 2 c) 5
b) 4 d) 8