+ 1
How to replace two words in Python?
name =("hello world") print(name.replace("h""w" , "c""t"))
5 Antworten
+ 2
I think you are trying to replace "h" with "c" and "w" with "t", in which case you should do this:
name = "hello world"
name = name.replace("h", "c").replace("w", "t")
print(name) # "cello torld"
I agree with everything else the others have already said 👍
+ 1
name = "Hello World"
def replaceWord(name, wtr):
for w, ww in wtr.items():
name = name.replace(w, ww)
return name
name = replaceWord(name, {"H":'C', "W":'T'})
print(name)
+ 1
name =("hello world")
print(name.replace("h","w",1).replace("u","h",2)) not work
+ 1
Hi
0
🥀Priya Singh🥀 What is the output you want?