How to replace word in a string in Python without using replace function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to replace word in a string in Python without using replace function?

5th Dec 2019, 5:57 PM
Himani Dalal
Himani Dalal - avatar
2 Answers
+ 6
The normal procedure in SL is that if you ask for help from the community, you first should go as far as you can, then publish your code here. Is there anything you can show? You can use several technical approaches, but I would recommend 2 common ones: #Using string - Use find() to get position of word to replace in string - Use string with slices - Add new word - Add the rest of the string # Using list - Split string to a list of words - Find index of string to replace - Replace old word by new word - put list back to a string with join()
5th Dec 2019, 8:11 PM
Lothar
Lothar - avatar