Computer Science

Identify the output of the following code snippet:

text = "PYTHONPROGRAM"
text = text.replace('PY', '#')
print(text)
  1. #THONPROGRAM
  2. ##THON#ROGRAM
  3. #THON#ROGRAM
  4. #YTHON#ROGRAM

Python String Manipulation

3 Likes

Answer

#THONPROGRAM

Reason — The replace() method in Python searches for a specified substring and replaces it with another. In the given code, the substring 'PY' in the string "PYTHONPROGRAM" is replaced with the character '#'. As a result, the string "PYTHONPROGRAM" becomes "#THONPROGRAM", and that's the output displayed.

Answered By

1 Like


Related Questions