Identify the output of the following Python program segment: S='Python…

2023

Identify the output of the following Python program segment: S='Python Programming' L=S.split() S=','.join(L) print(S)

  1. A.

    Python Programming / Python Programming

  2. B.

    Python,Programming / Python,Programming

  3. C.

    Python Programming, / Python Programming

  4. D.

    Python, Programming, / Python, Programming

Attempted by 1411 students.

Show answer & explanation

Correct answer: B

Key idea: split the string into words, then join them with a comma.

  • S = 'Python Programming' — original string contains two words separated by a space.

  • L = S.split() — split() with no argument splits on whitespace, producing the list ['Python', 'Programming'].

  • S = ','.join(L) — join the list items with ',' between them, producing the string 'Python,Programming'.

  • print(S) prints: Python,Programming

Explore the full course: Rssb Senior Computer Instructor