Remove a prefix from a string
Short and sweet:
def remove_prefix(text, prefix):
return text[text.startswith(prefix) and len(prefix):]
I don't know about "standard way".
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text # or whatever
As noted by @Boris and @Stefan, on Python 3.9+ you can use
text.removeprefix(prefix)
with the same behavior.