Python - MCQ Questions and Answers

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

« First 4 5 6 7 Last »
« Previous Page Next Page »

81. What is the output of print(3 * 'ab')?

  • a) ababab
  • b) 3ab
  • c) ab3
  • d) Error
Answer: A - Strings can be multiplied by integers to repeat them.

82. Which method returns the index of the first occurrence of a value in a list?

  • a) index()
  • b) find()
  • c) search()
  • d) locate()
Answer: A - ['a','b'].index('b') returns 1.

83. What does the zip() function do?

  • a) Combines iterables element-wise
  • b) Compresses files
  • c) Merges dictionaries
  • d) Concatenates strings
Answer: A - list(zip([1,2], ['a','b'])) returns [(1,'a'), (2,'b')].

84. Which function returns the largest item in an iterable?

  • a) max()
  • b) maximum()
  • c) largest()
  • d) top()
Answer: A - max([1,2,3]) returns 3.

85. What is the output of print('Python'[-1])?

  • a) n
  • b) P
  • c) o
  • d) Error
Answer: A - Negative indices count from the end (-1 is last character).

86. Which method splits a string at occurrences of a separator?

  • a) split()
  • b) partition()
  • c) divide()
  • d) separate()
Answer: A - 'a,b'.split(',') returns ['a','b'].

87. What is the output of print(bool([]))?

  • a) False
  • b) True
  • c) []
  • d) None
Answer: A - Empty lists are falsy in Python.

88. Which method returns a copy of a list in reverse order?

  • a) reversed()
  • b) reverse()
  • c) backwards()
  • d) flip()
Answer: A - list(reversed([1,2])) returns [2,1] (doesn't modify original).

89. What does the any() function do?

  • a) Returns True if any element is truthy
  • b) Checks if all elements are True
  • c) Counts truthy elements
  • d) Applies OR operation
Answer: A - any([False, 0, 'a']) returns True.

90. Which method converts a list to a string with elements separated by commas?

  • a) join()
  • b) str()
  • c) concat()
  • d) tostring()
Answer: A - ','.join(['a','b']) returns 'a,b'.

91. What is the output of print('Python'.islower())?

  • a) False
  • b) True
  • c) None
  • d) Error
Answer: A - Checks if all cased characters are lowercase (fails due to 'P').

92. Which method removes and returns the last item of a list?

  • a) pop()
  • b) remove()
  • c) delete()
  • d) cut()
Answer: A - my_list.pop() removes and returns the last item.

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

  • a) yth
  • b) Pyt
  • c) ytho
  • d) Python
Answer: A - Slicing includes start index (1) up to but not including stop index (4).

94. Which function returns a sequence of numbers?

  • a) range()
  • b) sequence()
  • c) numbers()
  • d) seq()
Answer: A - range(3) generates 0,1,2.

95. What does the enumerate() function do?

  • a) Adds counter to an iterable
  • b) Counts elements
  • c) Numbers items
  • d) Creates a numbered list
Answer: A - list(enumerate(['a'])) returns [(0,'a')].

96. Which method returns a list of dictionary keys?

  • a) keys()
  • b) get_keys()
  • c) items()
  • d) values()
Answer: A - my_dict.keys() returns a view of all keys.

97. What is the output of print('Python'.endswith('on'))?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - Checks if string ends with the specified suffix.

98. Which method removes whitespace from both ends of a string?

  • a) strip()
  • b) trim()
  • c) clean()
  • d) clear()
Answer: A - ' hello '.strip() returns 'hello'.

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

  • a) Pto
  • b) yhn
  • c) Python
  • d) Pyth
Answer: A - Step value of 2 selects every second character.

100. Which function returns the smallest item in an iterable?

  • a) min()
  • b) minimum()
  • c) smallest()
  • d) bottom()
Answer: A - min([1,2,3]) returns 1.
« First 4 5 6 7 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.