100 Most Important MCQ Questions on Python from "Lists and Tuple" || Python Programming || Computer Technology || Edu Verse By Pratik || Code With Pratik

Python Lists and Tuples Quiz - Part 2

1. What is the output of the following code?
my_list = [10, 20, 30, 40]
my_list.append(50)
print(my_list)

  • A. [10, 20, 30, 40, 50]
  • B. [10, 20, 30, 50]
  • C. [50, 10, 20, 30, 40]
  • D. Error

Answer: A. [10, 20, 30, 40, 50]

2. How do you access the last element of a list?

  • A. list[len(list)]
  • B. list[-1]
  • C. list[0]
  • D. list[last]

Answer: B. list[-1]

3. Which of the following is an immutable data type in Python?

  • A. List
  • B. Tuple
  • C. Dictionary
  • D. Set

Answer: B. Tuple

4. What will be the result of this code?
my_tuple = (1, 2, 3, 4)
my_tuple[1] = 5

  • A. (1, 5, 3, 4)
  • B. (1, 2, 3, 4)
  • C. Error
  • D. (5, 2, 3, 4)

Answer: C. Error

5. Which of the following methods is used to combine two lists?

  • A. extend()
  • B. append()
  • C. add()
  • D. join()

Answer: A. extend()

6. Which function can you use to get the number of elements in a tuple?

  • A. count()
  • B. length()
  • C. len()
  • D. size()

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])

  • A. [1, 2, 3]
  • B. [2, 3, 4]
  • C. [3, 4, 5]
  • D. [2, 3]

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)

  • A. [1, 2, 3, 4]
  • B. [1, 2, 4]
  • C. [1, 2, 3]
  • D. Error

Answer: B. [1, 2, 4]

9. How can you access the first element in a tuple named my_tuple?

  • A. my_tuple[1]
  • B. my_tuple[0]
  • C. my_tuple.first()
  • D. my_tuple[-1]

Answer: B. my_tuple[0]

10. Which method can be used to insert an item at a specific position in a list?

  • A. insert()
  • B. append()
  • C. add()
  • D. extend()

Answer: A. insert()

11. What is the output of the following code?
my_tuple = (1, 2, 3)
print(my_tuple[-1])

  • A. 1
  • B. 2
  • C. 3
  • D. Error

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)

  • A. ['a', 'x', 'y', 'd']
  • B. ['a', 'x', 'b', 'c', 'd']
  • C. ['a', 'y', 'd']
  • D. ['x', 'y', 'c', 'd']

Answer: A. ['a', 'x', 'y', 'd']

13. What is the correct way to convert a list into a tuple?

  • A. tuple(list)
  • B. convert_to_tuple(list)
  • C. list.to_tuple()
  • D. tupleify(list)

Answer: A. tuple(list)

14. Which of the following methods can you use to find the index of an item in a list?

  • A. find()
  • B. index()
  • C. search()
  • D. locate()

Answer: B. index()

15. Which method can you use to sort a list?

  • A. order()
  • B. arrange()
  • C. sort()
  • D. sequence()

Answer: C. sort()

16. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[::-1])

  • A. [1, 2, 3, 4, 5]
  • B. [5, 4, 3, 2, 1]
  • C. [5, 4, 3]
  • D. Error

Answer: B. [5, 4, 3, 2, 1]

17. How do you create a list with a single element?

  • A. my_list = (1)
  • B. my_list = [1]
  • C. my_list = 1
  • D. my_list = {1}

Answer: B. my_list = [1]

18. How can you remove an element by its index from a list?

  • A. remove()
  • B. delete()
  • C. del list[index]
  • D. pop()

Answer: C. del list[index]

19. How do you access the second last element in a list?

  • A. list[-2]
  • B. list[len(list)-2]
  • C. list[1]
  • D. list[last - 1]

Answer: A. list[-2]

20. Which of the following is a correct way to initialize an empty list?

  • A. []
  • B. ()
  • C. {}
  • D. None

Answer: A. []

21. What will be the output of the following code?
my_tuple = ('a', 'b', 'c', 'd')
print(my_tuple[1:3])

  • A. ('a', 'b')
  • B. ('b', 'c')
  • C. ('b', 'c', 'd')
  • D. ('c', 'd')

Answer: B. ('b', 'c')

22. What is the correct way to reverse a list?

  • A. list[::-1]
  • B. reverse(list)
  • C. list.reverse()
  • D. Both A and C

Answer: D. Both A and C

23. How can you find the number of times an item appears in a list?

  • A. len()
  • B. count()
  • C. index()
  • D. find()

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)

  • A. [1, 2, 3, 4, 5]
  • B. [1, 2, 3, [4, 5]]
  • C. [1, 2, 3]
  • D. Error

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'))

  • A. ('x', 'y', 'z')
  • B. ('x', 'y', 'z', 'a', 'b')
  • C. ('a', 'b', 'x', 'y', 'z')
  • D. Error

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])

  • A. [4, 3]
  • B. [4, 3, 2]
  • C. [3, 4]
  • D. [2, 3, 4]

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)

  • A. [1, 2, 7, 8, 5]
  • B. [1, 7, 8, 5]
  • C. [7, 8, 3, 4, 5]
  • D. [1, 2, 7, 4, 5]

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?

  • A. insert()
  • B. append()
  • C. extend()
  • D. add()

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)

  • A. ('a', 'b', 'c')
  • B. ('a', 'b', 'c', 'd')
  • C. ('d', 'a', 'b', 'c')
  • D. Error

Answer: B. ('a', 'b', 'c', 'd')

30. Which of the following is a tuple?

  • A. ['a', 'b', 'c']
  • B. ['a', 'b', 'c',]
  • C. ('a', 'b', 'c')
  • D. {'a', 'b', 'c'}

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)

  • A. ['a', 'b']
  • B. ['a', 'b', 'c']
  • C. ['a', 'c']
  • D. ['b', 'c']

Answer: A. ['a', 'b']

32. How can you convert a tuple to a list?

  • A. list(tuple)
  • B. convert_to_list(tuple)
  • C. tuple.to_list()
  • D. listify(tuple)

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)

  • A. True
  • B. False
  • C. Error
  • D. None

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)

  • A. []
  • B. [1, 2, 3, 4, 5]
  • C. None
  • D. Error

Answer: A. []

35. Which of the following will throw an error?

  • A. my_tuple = ('a', 'b', 'c')
  • B. my_tuple[1] = 'd'
  • C. my_tuple = my_tuple + ('d',)
  • D. print(my_tuple[1])

Answer: B. my_tuple[1] = 'd'

36. What does the following code output?
my_list = [10, 20, 30]
print(len(my_list))

  • A. 2
  • B. 3
  • C. 4
  • D. Error

Answer: B. 3

37. Which of the following methods will remove the item at a specific index in a list?

  • A. remove()
  • B. pop()
  • C. del
  • D. clear()

Answer: C. del

38. How do you create an empty tuple?

  • A. ()
  • B. []
  • C. {}
  • D. tuple()

Answer: A. ()

39. What is the output of the following code?
my_tuple = (1, 2, 3, 4)
print(my_tuple[1:3])

  • A. (1, 2, 3)
  • B. (2, 3, 4)
  • C. (2, 3)
  • D. (1, 3)

Answer: C. (2, 3)

40. What is the difference between extend() and append() in lists?

  • A. extend() adds each element from an iterable, append() adds the iterable itself
  • B. extend() adds the iterable itself, append() adds each element
  • C. Both are the same
  • D. Neither modifies the list

Answer: A. extend() adds each element from an iterable, append() adds the iterable itself

41. Which of the following is true about tuples?

  • A. Tuples are immutable
  • B. Tuples are mutable
  • C. Tuples can have their elements modified
  • D. Tuples cannot be sliced

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])

  • A. 2
  • B. 3
  • C. 4
  • D. 5

Answer: C. 4

43. What will be the output of the following code?
my_tuple = ('a', 'b', 'c', 'd')
print(my_tuple[::2])

  • A. ('a', 'b', 'c', 'd')
  • B. ('a', 'c')
  • C. ('b', 'd')
  • D. Error

Answer: B. ('a', 'c')

44. How can you access the last element of a list?

  • A. my_list[-1]
  • B. my_list[len(my_list)-1]
  • C. Both A and B
  • D. my_list[last]

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)

  • A. [1, 2, 4, 5]
  • B. [1, 2, 3, 4, 5]
  • C. [1, 2, 5]
  • D. [2, 3, 4, 5]

Answer: A. [1, 2, 4, 5]

46. How do you create a tuple with one item?

  • A. (item)
  • B. (item,)
  • C. (item, item)
  • D. tuple(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])

  • A. [0, 1]
  • B. [1, 2]
  • C. [2, 3]
  • D. [3, 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))

  • A. 3
  • B. 4
  • C. 5
  • D. 6

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)

  • A. [1, 2, 'a', 3, 4, 5]
  • B. [1, 'a', 2, 3, 4, 5]
  • C. ['a', 1, 2, 3, 4, 5]
  • D. [1, 2, 3, 4, 'a', 5]

Answer: A. [1, 2, 'a', 3, 4, 5]

50. Which of the following will create a list of even numbers between 1 and 10?

  • A. list(range(2, 10, 2))
  • B. [x for x in range(1, 11) if x % 2 == 0]
  • C. Both A and B
  • D. None of the above

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])

  • A. 3
  • B. 4
  • C. [3, 4]
  • D. Error

Answer: B. 4

52. What does the count() method do in a list?

  • A. Counts the number of elements
  • B. Counts the occurrence of a specified element
  • C. Counts the length of the list
  • D. Counts the total sum of elements

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))

  • A. tuple
  • B. list
  • C. set
  • D. dict

Answer: A. tuple

54. Which of the following is used to create a list in Python?

  • A. []
  • B. {}
  • C. ()
  • D. <>

Answer: A. []

55. What is the result of the following code?
my_list = [1, 2, 3] * 2
print(my_list)

  • A. [1, 2, 3, 1, 2, 3]
  • B. [2, 4, 6]
  • C. [1, 1, 2, 2, 3, 3]
  • D. [1, 2, 3, 4, 5, 6]

Answer: A. [1, 2, 3, 1, 2, 3]

56. Which method can be used to sort a list in Python?

  • A. sort()
  • B. order()
  • C. arrange()
  • D. set()

Answer: A. sort()

57. How can you concatenate two tuples?

  • A. Using + operator
  • B. Using * operator
  • C. Using append() method
  • D. Using extend() method

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)

  • A. [1, 4, 5, 3]
  • B. [1, 4, 5]
  • C. [4, 5, 3]
  • D. [1, 2, 3, 4, 5]

Answer: A. [1, 4, 5, 3]

59. What does the index() method do in a list?

  • A. Finds the index of the first occurrence of an element
  • B. Inserts an element at a specified index
  • C. Deletes an element at a specified index
  • D. Counts the occurrences of an element

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?

  • A. [value] * n
  • B. [value for _ in range(n)]
  • C. list([value] * n)
  • D. Both A and B

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)

  • A. [10, 2, 3]
  • B. [1, 10, 3]
  • C. [10, 10, 10]
  • D. [1, 2, 10]

Answer: A. [10, 2, 3]

62. How do you remove all occurrences of a specific element from a list?

  • A. Using remove()
  • B. Using pop()
  • C. Using a loop with remove()
  • D. Using clear()

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)

  • A. (1, 2, 3, 4)
  • B. (1, 2, 3, (4,))
  • C. (1, 2, 3, 4,)
  • D. (1, 2, 3, 4, 4)

Answer: A. (1, 2, 3, 4)

64. How can you access the last element of a tuple?

  • A. tuple[-1]
  • B. tuple[0]
  • C. tuple.last()
  • D. tuple[len(tuple)]

Answer: A. tuple[-1]

65. What does the pop() method do in a list?

  • A. Adds an element to the end
  • B. Removes an element at a specified index
  • C. Removes the first element
  • D. Adds an element at a specified index

Answer: B. Removes an element at a specified index

66. Which of the following is not a method available for lists in Python?

  • A. insert()
  • B. append()
  • C. reverse()
  • D. sort()
  • E. merge()

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)

  • A. [1, 2, 3, [4, 5]]
  • B. [1, 2, 3, 4, 5]
  • C. [1, 2, 3] + [4, 5]
  • D. [1, 2, 3] - [4, 5]

Answer: A. [1, 2, 3, [4, 5]]

68. Which method is used to remove a specific element from a tuple?

  • A. remove()
  • B. pop()
  • C. delete()
  • D. Tuples cannot be modified

Answer: D. Tuples cannot be modified

69. What does the extend() method do in a list?

  • A. Adds a single element
  • B. Adds multiple elements
  • C. Removes the first element
  • D. Removes a specified element

Answer: B. Adds multiple elements

70. How can you create a tuple with one element?

  • A. (1)
  • B. (1,)
  • C. tuple(1)
  • D. [1]

Answer: B. (1,)

71. What will be the output of the following code?
my_list = [1, 2, 3, 4, 5]
print(my_list[:3])

  • A. [1, 2, 3]
  • B. [2, 3, 4]
  • C. [1, 2, 3, 4]
  • D. [3, 4, 5]

Answer: A. [1, 2, 3]

72. How do you combine two lists in Python?

  • A. Using + operator
  • B. Using * operator
  • C. Using concat() method
  • D. Using append() method

Answer: A. Using + operator

73. What does the clear() method do in a list?

  • A. Removes all elements from the list
  • B. Removes the first element
  • C. Removes the last element
  • D. Removes a specified element

Answer: A. Removes all elements from the list

74. Which method is used to remove an element at a specific index in a list?

  • A. remove()
  • B. pop()
  • C. delete()
  • D. discard()

Answer: B. pop()

75. How can you find the length of a tuple?

  • A. len(tuple)
  • B. size(tuple)
  • C. length(tuple)
  • D. count(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)

  • A. [1, 4, 5, 2, 3]
  • B. [1, 2, 4, 5, 3]
  • C. [1, 4, 5, 2, 3]
  • D. [4, 5, 1, 2, 3]

Answer: A. [1, 4, 5, 2, 3]

77. How do you convert a list to a tuple in Python?

  • A. Using tuple() function
  • B. Using list() function
  • C. Using convert() method
  • D. Using change() method

Answer: A. Using tuple() function

78. Which method would you use to find if an element exists in a list?

  • A. exists()
  • B. find()
  • C. index()
  • D. in operator

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)

  • A. (1, 2, 3, 4, 5)
  • B. (1, 2, 3) + (4, 5)
  • C. (1, 2, 3, (4, 5))
  • D. (1, 2, 3, 4, 5, 4, 5)

Answer: A. (1, 2, 3, 4, 5)

80. How can you check if two lists are equal?

  • A. Using == operator
  • B. Using is operator
  • C. Using compare() method
  • D. Using equal() method

Answer: A. Using == operator

81. What is the result of the following code?
my_list = [1, 2, 3] * 0
print(my_list)

  • A. []
  • B. [0]
  • C. [1, 2, 3]
  • D. [1, 1, 1]

Answer: A. []

82. How do you add an element at a specific position in a list?

  • A. Using insert() method
  • B. Using append() method
  • C. Using add() method
  • D. Using extend() method

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)

  • A. (1, 2, 3, 1, 2, 3)
  • B. (1, 2, 3, 2, 3, 1)
  • C. (1, 2, 3, 2, 3, 2)
  • D. (1, 2, 3) * 2

Answer: A. (1, 2, 3, 1, 2, 3)

84. How can you concatenate two tuples?

  • A. Using + operator
  • B. Using append() method
  • C. Using extend() method
  • D. Using merge() method

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])

  • A. [5, 4, 3, 2, 1]
  • B. [1, 2, 3, 4, 5]
  • C. [5, 4, 3]
  • D. [4, 5]

Answer: A. [5, 4, 3, 2, 1]

86. Which of the following methods adds an element at the end of the list?

  • A. insert()
  • B. append()
  • C. add()
  • D. extend()

Answer: B. append()

87. How can you convert a tuple to a list?

  • A. Using list() function
  • B. Using tuple() function
  • C. Using convert() method
  • D. Using change() method

Answer: A. Using list() function

88. What is the result of the following code?
my_tuple = (1, 2, 3, 4)
print(my_tuple[2:])

  • A. (3, 4)
  • B. (2, 3, 4)
  • C. (3, 4, 2)
  • D. (2, 4)

Answer: A. (3, 4)

89. How do you check if a list is empty?

  • A. Using len(list) == 0
  • B. Using is_empty(list)
  • C. Using list.empty()
  • D. Using list.length == 0

Answer: A. Using len(list) == 0

90. What does the sort() method do to a list?

  • A. Sorts the list in ascending order
  • B. Sorts the list in descending order
  • C. Reverses the order of the list
  • D. Removes duplicates from the 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)

  • A. [1, 2, 3, 1, 2, 3]
  • B. [2, 4, 6]
  • C. [1, 2, 3, 2, 4, 6]
  • D. [1, 1, 2, 2, 3, 3]

Answer: A. [1, 2, 3, 1, 2, 3]

92. How do you find the index of an element in a list?

  • A. Using index() method
  • B. Using find() method
  • C. Using search() method
  • D. Using locate() method

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)

  • A. [10, 2, 20, 4, 30]
  • B. [10, 20, 30, 4, 5]
  • C. [10, 2, 3, 20, 30]
  • D. [1, 2, 3, 4, 5]

Answer: A. [10, 2, 20, 4, 30]

94. How can you find the number of occurrences of an element in a list?

  • A. Using count() method
  • B. Using frequency() method
  • C. Using occurrences() method
  • D. Using find() method

Answer: A. Using count() method

95. How can you concatenate two tuples?

  • A. Using + operator
  • B. Using concat() method
  • C. Using append() method
  • D. Using extend() method

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)

  • A. (0, 2, 3)
  • B. TypeError: 'tuple' object does not support item assignment
  • C. (1, 0, 3)
  • D. (1, 2, 3, 0)

Answer: B. TypeError: 'tuple' object does not support item assignment

97. How can you create a list with elements of different data types?

  • A. By simply adding elements of different types
  • B. Using list() function
  • C. Using mixed() method
  • D. Using append() method

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)

  • A. [1, 4, 5, 6]
  • B. [1, 2, 4, 5, 6]
  • C. [1, 4, 5]
  • D. [4, 5, 6]

Answer: A. [1, 4, 5, 6]

99. How can you create a tuple with a single element?

  • A. By adding a trailing comma
  • B. By enclosing the element in square brackets
  • C. By using tuple() function
  • D. By using list() function

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])

  • A. 4
  • B. [3, 4]
  • C. 3
  • D. [1, 2, [3, 4]]

Answer: A. 4

Thankyou so much for visiting here, if you like this mcq questions then share it with your frieds by your social medias platforms.
thanks.

Post a Comment

Previous Post Next Post