1. What is the output of the following code?
my_list = [10, 20, 30, 40]
my_list.append(50)
print(my_list)
Answer: A. [10, 20, 30, 40, 50]
2. How do you access the last element of a list?
Answer: B. list[-1]
3. Which of the following is an immutable data type in Python?
Answer: B. Tuple
4. What will be the result of this code?
my_tuple = (1, 2, 3, 4)
my_tuple[1] = 5
Answer: C. Error
5. Which of the following methods is used to combine two lists?
Answer: A. extend()
6. Which function can you use to get the number of elements in a tuple?
Answer: C. len()
7. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[1:4])
Answer: B. [2, 3, 4]
8. What is the result of the following code?
my_list = [1, 2, 3, 4]
my_list.remove(3)
print(my_list)
Answer: B. [1, 2, 4]
9. How can you access the first element in a tuple named my_tuple
?
Answer: B. my_tuple[0]
10. Which method can be used to insert an item at a specific position in a list?
Answer: A. insert()
11. What is the output of the following code?
my_tuple = (1, 2, 3)
print(my_tuple[-1])
Answer: C. 3
12. What will be the output of the following code?
my_list = ['a', 'b', 'c', 'd']
my_list[1:3] = ['x', 'y']
print(my_list)
Answer: A. ['a', 'x', 'y', 'd']
13. What is the correct way to convert a list into a tuple?
Answer: A. tuple(list)
14. Which of the following methods can you use to find the index of an item in a list?
Answer: B. index()
15. Which method can you use to sort a list?
Answer: C. sort()
16. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[::-1])
Answer: B. [5, 4, 3, 2, 1]
17. How do you create a list with a single element?
Answer: B. my_list = [1]
18. How can you remove an element by its index from a list?
Answer: C. del list[index]
19. How do you access the second last element in a list?
Answer: A. list[-2]
20. Which of the following is a correct way to initialize an empty list?
Answer: A. []
21. What will be the output of the following code?
my_tuple = ('a', 'b', 'c', 'd')
print(my_tuple[1:3])
Answer: B. ('b', 'c')
22. What is the correct way to reverse a list?
Answer: D. Both A and C
23. How can you find the number of times an item appears in a list?
Answer: B. count()
24. What will be the output of the following code?
my_list = [1, 2, 3]
my_list.append([4, 5])
print(my_list)
Answer: B. [1, 2, 3, [4, 5]]
25. What will be the output of the following code?
my_tuple = ('x', 'y', 'z')
print(my_tuple + ('a', 'b'))
Answer: B. ('x', 'y', 'z', 'a', 'b')
26. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[3:1:-1])
Answer: A. [4, 3]
27. What is the result of the following code?
my_list = [1, 2, 3, 4, 5]
my_list[2:4] = [7, 8]
print(my_list)
Answer: A. [1, 2, 7, 8, 5]
28. Which of the following methods would you use to add an item to the end of a list?
Answer: B. append()
29. What will be the output of the following code?
my_tuple = ('a', 'b', 'c')
my_tuple = my_tuple + ('d',)
print(my_tuple)
Answer: B. ('a', 'b', 'c', 'd')
30. Which of the following is a tuple?
Answer: C. ('a', 'b', 'c')
31. What will be the result of the following code?
my_list = ['a', 'b', 'c']
my_list.pop()
print(my_list)
Answer: A. ['a', 'b']
32. How can you convert a tuple to a list?
Answer: A. list(tuple)
33. What will be the result of the following code?
my_list = ['a', 'b', 'c', 'd']
print('e' in my_list)
Answer: B. False
34. What is the result of the following code?
my_list = [1, 2, 3, 4, 5]
my_list.clear()
print(my_list)
Answer: A. []
35. Which of the following will throw an error?
Answer: B. my_tuple[1] = 'd'
36. What does the following code output?
my_list = [10, 20, 30]
print(len(my_list))
Answer: B. 3
37. Which of the following methods will remove the item at a specific index in a list?
Answer: C. del
38. How do you create an empty tuple?
Answer: A. ()
39. What is the output of the following code?
my_tuple = (1, 2, 3, 4)
print(my_tuple[1:3])
Answer: C. (2, 3)
40. What is the difference between extend()
and append()
in lists?
Answer: A. extend()
adds each element from an iterable, append()
adds the iterable itself
41. Which of the following is true about tuples?
Answer: A. Tuples are immutable
42. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[-2])
Answer: C. 4
43. What will be the output of the following code?
my_tuple = ('a', 'b', 'c', 'd')
print(my_tuple[::2])
Answer: B. ('a', 'c')
44. How can you access the last element of a list?
Answer: C. Both A and B
45. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
my_list.remove(3)
print(my_list)
Answer: A. [1, 2, 4, 5]
46. How do you create a tuple with one item?
Answer: B. (item,)
47. What is the result of the following code?
my_list = [0, 1, 2, 3, 4]
print(my_list[2:4])
Answer: C. [2, 3]
48. What will be the result of the following code?
my_tuple = (1, 2, 3) + (4, 5)
print(len(my_tuple))
Answer: C. 5
49. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
my_list.insert(2, 'a')
print(my_list)
Answer: A. [1, 2, 'a', 3, 4, 5]
50. Which of the following will create a list of even numbers between 1 and 10?
Answer: C. Both A and B
51. What will be the output of the following code?
my_list = [1, 2, [3, 4]]
print(my_list[2][1])
Answer: B. 4
52. What does the count()
method do in a list?
Answer: B. Counts the occurrence of a specified element
53. What will be the output of the following code?
my_tuple = (1, 2, 3)
print(type(my_tuple))
Answer: A. tuple
54. Which of the following is used to create a list in Python?
Answer: A. []
55. What is the result of the following code?
my_list = [1, 2, 3] * 2
print(my_list)
Answer: A. [1, 2, 3, 1, 2, 3]
56. Which method can be used to sort a list in Python?
Answer: A. sort()
57. How can you concatenate two tuples?
Answer: A. Using +
operator
58. What is the result of the following code?
my_list = [1, 2, 3]
my_list[1:2] = [4, 5]
print(my_list)
Answer: A. [1, 4, 5, 3]
59. What does the index()
method do in a list?
Answer: A. Finds the index of the first occurrence of an element
60. How can you create a list with all elements set to the same value?
Answer: D. Both A and B
61. What is the result of the following code?
my_list = [1, 2, 3]
my_list[0] = 10
print(my_list)
Answer: A. [10, 2, 3]
62. How do you remove all occurrences of a specific element from a list?
Answer: C. Using a loop with remove()
63. What is the result of the following code?
my_tuple = (1, 2, 3) + (4,)
print(my_tuple)
Answer: A. (1, 2, 3, 4)
64. How can you access the last element of a tuple?
Answer: A. tuple[-1]
65. What does the pop()
method do in a list?
Answer: B. Removes an element at a specified index
66. Which of the following is not a method available for lists in Python?
Answer: E. merge()
67. What is the result of the following code?
my_list = [1, 2, 3]
my_list.append([4, 5])
print(my_list)
Answer: A. [1, 2, 3, [4, 5]]
68. Which method is used to remove a specific element from a tuple?
Answer: D. Tuples cannot be modified
69. What does the extend()
method do in a list?
Answer: B. Adds multiple elements
70. How can you create a tuple with one element?
Answer: B. (1,)
71. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[:3])
Answer: A. [1, 2, 3]
72. How do you combine two lists in Python?
Answer: A. Using +
operator
73. What does the clear()
method do in a list?
Answer: A. Removes all elements from the list
74. Which method is used to remove an element at a specific index in a list?
Answer: B. pop()
75. How can you find the length of a tuple?
Answer: A. len(tuple)
76. What will be the output of the following code?
my_list = [1, 2, 3]
my_list[1:1] = [4, 5]
print(my_list)
Answer: A. [1, 4, 5, 2, 3]
77. How do you convert a list to a tuple in Python?
Answer: A. Using tuple()
function
78. Which method would you use to find if an element exists in a list?
Answer: D. in
operator
79. What is the output of the following code?
my_tuple = (1, 2, 3)
my_tuple += (4, 5)
print(my_tuple)
Answer: A. (1, 2, 3, 4, 5)
80. How can you check if two lists are equal?
Answer: A. Using ==
operator
81. What is the result of the following code?
my_list = [1, 2, 3] * 0
print(my_list)
Answer: A. []
82. How do you add an element at a specific position in a list?
Answer: A. Using insert()
method
83. What is the result of the following code?
my_tuple = (1, 2, 3)
my_tuple *= 2
print(my_tuple)
Answer: A. (1, 2, 3, 1, 2, 3)
84. How can you concatenate two tuples?
Answer: A. Using +
operator
85. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[::-1])
Answer: A. [5, 4, 3, 2, 1]
86. Which of the following methods adds an element at the end of the list?
Answer: B. append()
87. How can you convert a tuple to a list?
Answer: A. Using list()
function
88. What is the result of the following code?
my_tuple = (1, 2, 3, 4)
print(my_tuple[2:])
Answer: A. (3, 4)
89. How do you check if a list is empty?
Answer: A. Using len(list) == 0
90. What does the sort()
method do to a list?
Answer: A. Sorts the list in ascending order
91. What will be the result of the following code?
my_list = [1, 2, 3]
my_list * 2
print(my_list)
Answer: A. [1, 2, 3, 1, 2, 3]
92. How do you find the index of an element in a list?
Answer: A. Using index()
method
93. What is the result of the following code?
my_list = [1, 2, 3, 4, 5]
my_list[::2] = [10, 20, 30]
print(my_list)
Answer: A. [10, 2, 20, 4, 30]
94. How can you find the number of occurrences of an element in a list?
Answer: A. Using count()
method
95. How can you concatenate two tuples?
Answer: A. Using +
operator
96. What will be the output of the following code?
my_tuple = (1, 2, 3)
my_tuple[0] = 0
print(my_tuple)
Answer: B. TypeError: 'tuple' object does not support item assignment
97. How can you create a list with elements of different data types?
Answer: A. By simply adding elements of different types
98. What is the result of the following code?
my_list = [1, 2, 3]
my_list[1:3] = [4, 5, 6]
print(my_list)
Answer: A. [1, 4, 5, 6]
99. How can you create a tuple with a single element?
Answer: A. By adding a trailing comma
100. What is the output of the following code?
my_list = [1, 2, [3, 4]]
print(my_list[2][1])
Answer: A. 4