Report Bug
Qus :

What will be the output of the following Python code?

print('abcd'.partition('cd'))

Qus

निम्नलिखित पायथन कोड का आउटपुट क्या होगा?

print('abcd'.partition('cd'))


A. (‘ab’, ‘cd’, ”)
B. (‘ab’, ‘cd’)
C. error
D. none of the mentioned


Solution
A. (‘ab’, ‘cd’, ”)



Explanation
The partition() method in Python splits a string into three parts based on a specified separator. It returns a tuple containing three elements:

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

Explanation:

The first element of the tuple is 'ab', which is the part of the string before the first occurrence of 'cd'.
The second element is 'cd', which is the separator itself.
The third element is an empty string '', which is the part of the string after the separator.
So, when you print the result, you'll see ('ab', 'cd', '').



Report Bug