Python - MCQ Questions and Answers

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

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

101. What is the output of print(round(3.14159, 2))?

  • a) 3.14
  • b) 3.142
  • c) 3.141
  • d) 3.15
Answer: A - round() with 2 as second argument rounds to 2 decimal places.

102. Which method checks if all characters in a string are digits?

  • a) isdigit()
  • b) isnumeric()
  • c) isdecimal()
  • d) isdigit() and isnumeric()
Answer: A - '123'.isdigit() returns True (but note Unicode differences).

103. What does list('abc') return?

  • a) ['a', 'b', 'c']
  • b) ['abc']
  • c) [97, 98, 99]
  • d) Error
Answer: A - Strings are iterable, so list() creates a list of characters.

104. Which operator performs floor division?

  • a) //
  • b) /
  • c) %
  • d) |
Answer: A - 5 // 2 returns 2 (discards remainder).

105. What is the output of print('Hello'.lower())?

  • a) hello
  • b) Hello
  • c) HELLO
  • d) hELLO
Answer: A - lower() converts all characters to lowercase.

106. Which method returns a string with first letter capitalized?

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

107. What is the output of print(2 ** 3 ** 2)?

  • a) 512
  • b) 64
  • c) 12
  • d) Error
Answer: A - Exponentiation is right-associative: 2^(3^2) = 2^9 = 512.

108. Which function returns the absolute value?

  • a) abs()
  • b) absolute()
  • c) fabs()
  • d) mod()
Answer: A - abs(-5) returns 5.

109. What does 'Hello'.swapcase() return?

  • a) hELLO
  • b) HELLO
  • c) hello
  • d) Error
Answer: A - Swaps uppercase to lowercase and vice versa.

110. Which method removes whitespace from the right end of a string?

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

111. What is the output of print('Python'.center(10, '*'))?

  • a) **Python**
  • b) Python****
  • c) ****Python
  • d) *Python*
Answer: A - Centers string in 10-character width, padded with *.

112. Which function returns the ASCII value of a character?

  • a) ord()
  • b) chr()
  • c) ascii()
  • d) code()
Answer: A - ord('A') returns 65.

113. What is the output of print('Python'.partition('th'))?

  • a) ('Py', 'th', 'on')
  • b) ['Py', 'th', 'on']
  • c) ('Python',)
  • d) Error
Answer: A - Returns 3-tuple: (before, separator, after).

114. Which method returns True if a string contains only whitespace?

  • a) isspace()
  • b) isempty()
  • c) isblank()
  • d) iswhitespace()
Answer: A - ' '.isspace() returns True.

115. What does print('Hello' + 'World') output?

  • a) HelloWorld
  • b) Hello World
  • c) 'Hello''World'
  • d) Error
Answer: A - Strings are concatenated without space.

116. Which function returns a character from an ASCII value?

  • a) chr()
  • b) ord()
  • c) char()
  • d) ascii()
Answer: A - chr(65) returns 'A'.

117. What is the output of print('Python'.replace('', '-'))?

  • a) -P-y-t-h-o-n-
  • b) Python
  • c) -Python-
  • d) Error
Answer: A - Empty string matches between all characters.

118. Which method returns a string with leading zeros?

  • a) zfill()
  • b) pad()
  • c) ljust()
  • d) zerofill()
Answer: A - '42'.zfill(5) returns '00042'.

119. What is the output of print('Python'.count('th'))?

  • a) 1
  • b) 2
  • c) 0
  • d) Error
Answer: A - Counts non-overlapping occurrences of substring.

120. Which method returns True if a string is titlecased?

  • a) istitle()
  • b) iscapitalized()
  • c) isproper()
  • d) isheading()
Answer: A - 'Hello World'.istitle() returns True.
« First 5 6 7 8 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.