Replace multiple words with certain words.

In this program, we will take a string as input and replace multiple words with certain words.

Steps to solve the program
  1. Take a string as input.
  2. Convert the string of words into a list of words using split().
  3. Use for loop with range() function to iterate over each word in the list.
  4. Replace the word in the string with a defined word.
  5. Convert the list into a string using join().
  6. Print the output.
				
					#Input string
string = "I’m learning python at Sqatools"
List = string.split(" ")

for i in range(len(List)):
    if List[i] == "python":
        List[i] = "SQA"
    elif List[i] == "Sqatools":
        List[i] = "TOOLS"

#Printing output        
print(" ".join(List))
				
			

Output :

				
					I’m learning SQA at TOOLS
				
			

split strings on vowels

replace different characters in the string at once.

Leave a Comment