Answers for "python string replace multiple words"

4

python substitute multiple letters

message = "h@ll$ w$rld"
# make the replacement ('!'->'a', '@'->'e', etc.)
message.translate(str.maketrans("!@#$%", "aeiou"))
# outputs hello world
Posted by: Guest on May-26-2021
1

replace multiple different substrings in python

s = 'one two three one two three one two'
print(s.replace('one', 'TWO').replace('two', 'ZZZ').replace('three', 'YYY'))

# Output -
# TWO ZZZ YYY TWO ZZZ YYY TWO ZZZ
Posted by: Guest on January-03-2022

Code answers related to "python string replace multiple words"

Python Answers by Framework

Browse Popular Code Answers by Language