Skip to content
Question 61 of 97

Q.Select the correct output of the code: S="Amrit Mahotsav @ 75" A=S.partition(" ") print(A)

(a) ('Amrit Mahotsav', '@', '75')
(b) ['Amrit', 'Mahotsav', '@', '75']
(c) ('Amrit', 'Mahotsav @ 75')
(d) ('Amrit', ' ', 'Mahotsav @ 75')
Tripura TbseCBSE Class XII Board 2023MCQ· 1mImportance★★★★★
63% · 61/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The partition() method splits a string into three parts at the first occurrence of the specified separator, returning a tuple. The output is ('Amrit', ' ', 'Mahotsav @ 75').

The core concept here revolves around understanding how Python's string partition() method works. Unlike split(), which can divide a string into many parts based on a separator and returns a list, partition() has a very specific job: it always divides the string into exactly three parts and returns them as a tuple.

Here's the breakdown of what those three parts are:

  1. The part of the string before the first occurrence of the separator.
  2. The separator itself.
  3. The part of the string after the first occurrence of the separator.

The key is "first occurrence." If the separator appears multiple times, partition() only considers the very first one it finds. If the separator is not found in the string, partition() returns a tuple containing the original string, followed by two empty strings ('', '').

Let's apply this to the given code.

  1. Identify the string and the separator.

    We have the string S = "Amrit Mahotsav @ 75".

    The partition() method is called with S.partition(" "), meaning the separator we are looking for is a single space character " ".

  2. Locate the first occurrence of the separator.

    In the string "Amrit Mahotsav @ 75", the first space character appears immediately after the word "Amrit".

    S = "Amrit Mahotsav @ 75"

    ^ (First space)

  3. Divide the string into three parts based on the first separator.

    • Part 1 (before the separator): Everything before the first space is "Amrit".
    • Part 2 (the separator itself): The separator is " ".
    • Part 3 (after the separator): Everything after the first space is "Mahotsav @ 75".
  4. Form the tuple.

    The partition() method returns these three parts as a tuple.

    So, A will be ('Amrit', ' ', 'Mahotsav @ 75'). …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.