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)
- A.
Python Programming / Python Programming
- B.
Python,Programming / Python,Programming
- C.
Python Programming, / Python Programming
- 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