I need to strip a specific word from a string.
But I find python strip method seems can't recognize an ordered word. The just strip off any characters passed to the parameter.
For example:
>>> papa = "papa is a good man"
>>> app = "app is important"
>>> papa.lstrip('papa')
" is a good man"
>>> app.lstrip('papa')
" is important"
How could I strip a specified word with python?
S.lstrip? It does something completely different to what you want to do. You want toreplacethis string with nothing. - Benjamin Bannierya. Lets wait for OP to confirm - thefourtheyeprint "papa is papa is papa".replace('papa', '')and if the output is fine with you, then the accepted answer is correct. - thefourtheyepapa.replace('man', ''). You will end up with'papa is a good '(notice the space after'good'. - Ely Fialkoff