Which of the following is the correct output of the given Python code? STR =…
2026
Which of the following is the correct output of the given Python code?
STR = "MIRROR OF FUTURE"
print(STR.partition("OF"))
Answer: A. ('MIRROR ', 'OF', ' FUTURE') — str.partition(sep) searches for the first occurrence of sep and returns a 3-tuple: (part_before_sep, sep, part_after_sep). It performs no trimming — any…
- A.
('MIRROR ', 'OF', ' FUTURE')
- B.
['MIRROR', 'OF', 'FUTURE']
- C.
('MIRROR', 'FUTURE')
- D.
['MIRROR', 'FUTURE']
Attempted by 244 students.
Show answer & explanation
Correct answer: A
str.partition(sep) searches for the first occurrence of sep and returns a 3-tuple: (part_before_sep, sep, part_after_sep). It performs no trimming — any characters adjacent to the separator in the original string, including spaces, are preserved exactly as they appear in the corresponding tuple element. If sep is absent, it returns (original_string, '', '').
STR holds "MIRROR OF FUTURE" and the call is STR.partition("OF").
Scanning left to right, the first "OF" appears right after "MIRROR " (the word MIRROR plus a trailing space), immediately before "FUTURE".
Everything before that match, "MIRROR " (including the trailing space), becomes the first tuple element.
The matched text "OF" itself becomes the second element.
Everything after the match, " FUTURE" (including the leading space), becomes the third element.
So STR.partition("OF") evaluates to ('MIRROR ', 'OF', ' FUTURE'), and print() outputs exactly that.
Concatenating the three returned pieces reproduces the original string exactly: 'MIRROR ' + 'OF' + ' FUTURE' == 'MIRROR OF FUTURE', confirming no character was added, dropped, or trimmed — the surrounding spaces belong to the first and third elements, not the separator.