-1

I would like to see how I could remove a certain section of a string without leaving the blank space.

When running this code it outputs nice today, the problem is that I am replacing the characters with a blank space. Is there a fix to this or should I be using a completely different method entirely?

text = ("hello bye there ")

print(text.replace("hello", "nice").replace("there","today").replace("bye", ""))
Brenduan
  • 9
  • 5

1 Answers1

0

you should remove white space at first:

text = ("hello bye there ")
print(text.replace("hello", "nice").replace("there","today").replace(" ", '').replace("bye" , " "))

the output will be:

nice today
Maryam
  • 660
  • 6
  • 19