PCEP-30-02 · Question #247
What is the expected output of the following code? print('x', 'y', 'z', sep='sep')
The correct answer is D. xsepysepz. Option D is correct because Python's print() function uses the sep parameter as the separator string inserted between each argument, so print('x', 'y', 'z', sep='sep') joins the three strings with the literal text "sep", producing xsepysepz. Option A (x y z) is wrong - that…
Question
Options
- Ax y z
- Bxyz
- Cxsepysepz
- Dxsepysepz
How the community answered
(20 responses)- A15% (3)
- B5% (1)
- C5% (1)
- D75% (15)
Explanation
Option D is correct because Python's print() function uses the sep parameter as the separator string inserted between each argument, so print('x', 'y', 'z', sep='sep') joins the three strings with the literal text "sep", producing xsepysepz.
Option A (x y z) is wrong - that would be the output with the default sep=' ' (a single space), which applies only when no sep argument is provided. Option B (xyz) is wrong - that would require sep='' (an empty string), which concatenates without any separator. Option C is identical to D in wording here (likely a typo in the question), but in typical exam variants C often shows x sep y sep z with surrounding spaces - which would require spaces built into the separator string, like sep=' sep '.
Memory tip: Think of sep as the glue poured between items - whatever string you assign to sep is exactly what appears between each printed argument, no more and no less.
Community Discussion
No community discussion yet for this question.