Replace the words in the given string

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
  1. Take a string as input.
  2. Convert the list into a list.
  3. Use For loop to iterate over each word in the string.
  4. If a word is equal to “JAVA” replace the word with “PYTHON”.
  5. combine the new list using join().
  6. 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
				
			

get all the digits from the given string.

get all the palindrome words from the string.

Leave a Comment