Python - MCQ Questions and Answers

Test your knowledge of Python with these interactive multiple-choice questions.

« First 6 7 8 9 Last »
« Previous Page Next Page »

121. What is the output of print([1, 2, 3] + [4, 5])?

  • a) [1, 2, 3, 4, 5]
  • b) [5, 7, 3]
  • c) [[1, 2, 3], [4, 5]]
  • d) Error
Answer: A - The + operator concatenates lists in Python.

122. Which method adds an element to the end of a list?

  • a) append()
  • b) add()
  • c) extend()
  • d) push()
Answer: A - my_list.append(x) adds x to the end of the list.

123. What does print(bool(' ')) output?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - A string with a space is non-empty and therefore truthy.

124. Which operator checks if two variables reference the same object?

  • a) is
  • b) ==
  • c) equals
  • d) same
Answer: A - The is operator checks for identity, not equality.

125. What is the output of print('Python'[1:])?

  • a) ython
  • b) Pytho
  • c) Python
  • d) ytho
Answer: A - Omitting the end index slices to the end of the string.

126. Which method adds elements from an iterable to a list?

  • a) extend()
  • b) append()
  • c) concat()
  • d) add_all()
Answer: A - my_list.extend([1,2]) adds multiple elements.

127. What is the output of print('Python'.find('Py'))?

  • a) 0
  • b) 1
  • c) True
  • d) -1
Answer: A - Returns the starting index of the substring (0 in this case).

128. Which method returns a list sorted in reverse?

  • a) sorted(my_list, reverse=True)
  • b) my_list.reverse_sorted()
  • c) my_list.sort(reverse=True)
  • d) reversed(my_list)
Answer: A - sorted() with reverse=True returns a new sorted list in descending order.

129. What does print('Python'[::-1]) output?

  • a) nohtyP
  • b) Python
  • c) P
  • d) Error
Answer: A - [::-1] reverses the string (step value of -1).

130. Which method returns the number of occurrences of a value in a list?

  • a) count()
  • b) occurrences()
  • c) find_all()
  • d) len()
Answer: A - my_list.count(x) counts how many times x appears.

131. What is the output of print('Python'.isalnum())?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - Checks if all characters are alphanumeric (letters or numbers).

132. Which method inserts an element at a specific position?

  • a) insert()
  • b) add_at()
  • c) push()
  • d) set()
Answer: A - my_list.insert(0, 'x') inserts at index 0.

133. What is the output of print('Python'.upper())?

  • a) PYTHON
  • b) python
  • c) Python
  • d) Error
Answer: A - Converts all characters to uppercase.

134. Which method removes all items from a list?

  • a) clear()
  • b) remove_all()
  • c) empty()
  • d) delete()
Answer: A - my_list.clear() empties the list.

135. What does print('Python'.split('th')) return?

  • a) ['Py', 'on']
  • b) ['P', 'on']
  • c) ['Python']
  • d) Error
Answer: A - Splits the string at each occurrence of the separator.

136. Which function returns a list of integers from start to stop?

  • a) range()
  • b) list_range()
  • c) sequence()
  • d) int_range()
Answer: A - list(range(3)) returns [0, 1, 2].

137. What is the output of print('Python'[0:6:2])?

  • a) Pto
  • b) yhn
  • c) Python
  • d) Pyth
Answer: A - Takes every second character from index 0 to 5.

138. Which method returns a shallow copy of a list?

  • a) copy()
  • b) clone()
  • c) duplicate()
  • d) list()
Answer: A - my_list.copy() creates a new list with the same elements.

139. What does print('Python' * 2) output?

  • a) PythonPython
  • b) Python2
  • c) Python Python
  • d) Error
Answer: A - Strings can be multiplied by integers to repeat them.

140. Which method returns the last index of a value in a list?

  • a) There is no built-in method for this
  • b) rindex()
  • c) last_index()
  • d) find_last()
Answer: A - Python lists don't have a built-in method for finding the last index (but strings have rfind()).
« First 6 7 8 9 Last »
« Previous Page Next Page »

Learn Computer Skills with PCBooks

Master computer skills with PCBooks! Explore interactive tutorials, MCQ tests, and online exams for programming, web development, and IT fundamentals. Perfect for beginners and advanced learners.

Online MCQ Tests for Programming

Practice programming MCQ questions and improve your coding skills with our online quizzes. Whether you're learning Python, Java, or C programming, PCBooks has you covered.

Free Web Development Tutorials

Learn HTML, CSS, and JavaScript with our free web development tutorials. Test your knowledge with interactive quizzes and online exams.