NIELIT O Level Exam

<p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">print('abcd'.partition('cd'))</span></pre>

What will be the output of the following Python code?

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


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

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

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

B. (‘ab’, ‘cd’)

C. error एरर

D. none of the mentioned उल्लेखित कोई नहीं




Correct Answer is :

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', '').
CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad