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…

  1. A.

    ('MIRROR ', 'OF', ' FUTURE')

  2. B.

    ['MIRROR', 'OF', 'FUTURE']

  3. C.

    ('MIRROR', 'FUTURE')

  4. D.

    ['MIRROR', 'FUTURE']

Attempted by 242 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, '', '').

  1. STR holds "MIRROR OF FUTURE" and the call is STR.partition("OF").

  2. Scanning left to right, the first "OF" appears right after "MIRROR " (the word MIRROR plus a trailing space), immediately before "FUTURE".

  3. Everything before that match, "MIRROR " (including the trailing space), becomes the first tuple element.

  4. The matched text "OF" itself becomes the second element.

  5. Everything after the match, " FUTURE" (including the leading space), becomes the third element.

  6. 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.

Explore the full course: Rssb Senior Computer Instructor

Loading lesson…