Python - MCQ Questions and Answers

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

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

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

  • a) y
  • b) P
  • c) t
  • d) h
Answer: A - Python uses 0-based indexing, so index 1 is the second character 'y'.

62. Which method converts a string to title case?

  • a) title()
  • b) capitalize()
  • c) upper()
  • d) titlize()
Answer: A - 'hello world'.title() returns 'Hello World'.

63. What does the join() method do?

  • a) Combines strings with a separator
  • b) Joins two lists
  • c) Concatenates dictionaries
  • d) Merges sets
Answer: A - '-'.join(['a','b']) returns 'a-b'.

64. Which operator checks if a value is in a sequence?

  • a) in
  • b) contains
  • c) exists
  • d) isin
Answer: A - 'a' in ['a','b'] returns True.

65. What is the output of print(bool('False'))?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - Non-empty strings are always truthy, regardless of content.

66. Which method removes the first occurrence of a value in a list?

  • a) remove()
  • b) pop()
  • c) delete()
  • d) discard()
Answer: A - my_list.remove(value) removes the first matching item.

67. What is the output of print('Python'.find('z'))?

  • a) -1
  • b) None
  • c) False
  • d) Error
Answer: A - find() returns -1 when substring isn't found.

68. Which function returns the length of an object?

  • a) len()
  • b) length()
  • c) size()
  • d) count()
Answer: A - len('Python') returns 6.

69. What is the output of print('Python'.startswith('Py'))?

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

70. Which method returns a list of dictionary values?

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

71. What does the all() function do?

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

72. Which Python data type is mutable and unordered?

  • a) set
  • b) tuple
  • c) list
  • d) str
Answer: A - Sets are mutable and unordered: {1, 2, 3}.

73. What is the output of print(bool(0))?

  • a) False
  • b) True
  • c) 0
  • d) None
Answer: A - Zero is falsy in Python.

74. Which function returns the sum of all items in an iterable?

  • a) sum()
  • b) total()
  • c) add()
  • d) aggregate()
Answer: A - sum([1,2,3]) returns 6.

75. What does sorted() function do?

  • a) Returns a new sorted list
  • b) Sorts the original list
  • c) Checks if list is sorted
  • d) Reverses the list
Answer: A - sorted() returns a new list without modifying the original.

76. Which module is used for working with regular expressions?

  • a) re
  • b) regex
  • c) pyre
  • d) string
Answer: A - The re module provides regex support.

77. What is the output of print('Python'.isalpha())?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - Checks if all characters are alphabetic (no spaces/numbers).

78. Which method removes whitespace from the left end of a string?

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

79. What is the output of print('Python'.replace('P', 'J'))?

  • a) Jython
  • b) Python
  • c) JythonP
  • d) Error
Answer: A - Replaces all occurrences of 'P' with 'J'.

80. Which function returns a list of tuples containing keys and values?

  • a) items()
  • b) pairs()
  • c) entries()
  • d) elements()
Answer: A - my_dict.items() returns key-value pairs.
« First 3 4 5 6 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.