101. What is the output of print(round(3.14159, 2))?
- a) 3.14
- b) 3.142
- c) 3.141
- d) 3.15
round() with 2 as second argument rounds to 2 decimal places.
Test your knowledge of Python with these interactive multiple-choice questions.
101. What is the output of print(round(3.14159, 2))?
round() with 2 as second argument rounds to 2 decimal places.
102. Which method checks if all characters in a string are digits?
'123'.isdigit() returns True (but note Unicode differences).
103. What does list('abc') return?
list() creates a list of characters.
104. Which operator performs floor division?
5 // 2 returns 2 (discards remainder).
105. What is the output of print('Hello'.lower())?
lower() converts all characters to lowercase.
106. Which method returns a string with first letter capitalized?
'hello'.capitalize() returns 'Hello'.
107. What is the output of print(2 ** 3 ** 2)?
108. Which function returns the absolute value?
abs(-5) returns 5.
109. What does 'Hello'.swapcase() return?
110. Which method removes whitespace from the right end of a string?
'hello '.rstrip() returns 'hello'.
111. What is the output of print('Python'.center(10, '*'))?
112. Which function returns the ASCII value of a character?
ord('A') returns 65.
113. What is the output of print('Python'.partition('th'))?
114. Which method returns True if a string contains only whitespace?
' '.isspace() returns True.
115. What does print('Hello' + 'World') output?
116. Which function returns a character from an ASCII value?
chr(65) returns 'A'.
117. What is the output of print('Python'.replace('', '-'))?
118. Which method returns a string with leading zeros?
'42'.zfill(5) returns '00042'.
119. What is the output of print('Python'.count('th'))?
120. Which method returns True if a string is titlecased?
'Hello World'.istitle() returns True.