In this program, we will take a string as input and replace the words “Java” with “Python” in the given string
Steps to solve the program
- Take a string as input.
- Convert the list into a list.
- Use For loop to iterate over each word in the string.
- If a word is equal to “JAVA” replace the word with “PYTHON”.
- combine the new list using join().
- Print the output.
#Input string
string = "JAVA is the Best Programming Language in the Market"
List1 = string.split(" ")
for word in List1:
if word == "JAVA":
index = List1.index(word)
List1[index] = "PYTHON"
#Printing output
print(" ".join(List1))
Output :
PYTHON is the Best Programming Language in the Market