Python string removeprefix() method
Remove some text from the start, if it is there.
Syntax
str.removeprefix(prefix)
Unlike lstrip, it removes that exact text once, not a set of characters.
Parameters
| prefix | the text to remove |
Return value
str
Example
Code
print("Mr Smith".removeprefix("Mr ")) print("Smith".removeprefix("Mr ")) print("www.site.com".lstrip("w."), "|", "www.site.com".removeprefix("www."))
Output
Smith Smith site.com | site.com
Related
Learn it step by step in the free lesson Strings, with exercises that check your answers.