KnowledgeBoat Logo

Computer Science

Select the correct output of the code:

s = "Python is fun"
l = s.split()
s_new = "-".join([l[0].upper(), l[1], l[2].capitalize()])
print(s_new)
  1. PYTHON-IS-Fun
  2. PYTHON-is-Fun
  3. Python-is-fun
  4. PYTHON-Is -Fun

Python String Manipulation

3 Likes

Answer

PYTHON-is-Fun

Reason — The code initializes a string variable s with the value 'Python is fun'. It splits the string into words using split() method, then converts the first word to uppercase ('PYTHON') using indexing and the upper() method, and capitalizes the third word ('Fun') with the capitalize() method. It then joins the modified words with a hyphen ('-') as the separator using the join() method and prints the result.

Answered By

3 Likes


Related Questions