Replace different characters in string at once.

In this program, we will take a string as input and replace different characters in string at once.

Steps to solve the program
  1. Take a string as input and create an empty string.
  2. Add each character from the given string to the empty string after replacing different characters.
  3. Use for loop for this purpose.
  4. Print the output.
				
					#Input string
string = "Sqatool python"
new_str = ""

for char in string:
    if char == "a":
        new_str += "1"
    elif char == "t":
        new_str += "2"
    elif char == "o":
        new_str += "3"
    else:
        new_str += char

#Printing output
print(new_str)
				
			

Output :

				
					Sq1233l py2h3n
				
			

replace multiple words with certain words.

remove empty spaces from a list of strings.

Leave a Comment