21. What is the output of print(3 * 'ab' + 'c')?
- a) ababc
- b) abababc
- c) abababcc
- d) abababc
'ab'*3 = 'ababab', then concatenates 'c'.
Test your knowledge of Python with these interactive multiple-choice questions.
21. What is the output of print(3 * 'ab' + 'c')?
'ab'*3 = 'ababab', then concatenates 'c'.
22. Which method removes all items from a dictionary?
my_dict.clear() empties the dictionary.
23. What does the pass statement do?
pass is a no-op statement used where syntax requires a statement but no action is needed.
24. Which module would you use for mathematical operations like sqrt?
math module provides mathematical functions: math.sqrt(4).
25. What is the output of print('Python'.find('th'))?
find() returns the lowest index where substring starts (0-based index).
26. How do you create a tuple with a single element?
(1,) vs (1) which is just parentheses.
27. What does sys.argv contain?
sys.argv is a list of command-line arguments passed to the script.
28. Which operator checks if two variables reference the same object?
is checks identity (same memory location), while == checks equality.
29. What is the output of print('Hello'.replace('l', 'L', 1))?
30. Which method returns a list of dictionary keys?
my_dict.keys() returns a view of all keys (use list() to convert to list).
31. What does the else clause in a for loop do?
elifelse in loops executes only if no break occurred.
32. Which Python data type is immutable and ordered?
(1, 2, 3).
33. What is the output of print(bool([]))?
34. Which function returns the absolute value of a number?
abs(-5) returns 5.
35. What does zip() function do?
zip([1,2], ['a','b']) yields (1,'a'), (2,'b').
36. Which module is used for working with dates?
datetime module provides date/time manipulation classes.
37. What is the output of print('Python'.islower())?
38. Which method splits a string at line breaks?
splitlines() handles different line endings (\n, \r, etc.).
39. What is the output of print(round(3.14159, 2))?
40. Which function returns the smallest item in an iterable?
min([3,1,4]) returns 1.