Question

How to remove a prefix or a substring at the beginning of a string in Python?


Annonce
Ad

Answer

output = string[string.startswith(prefix) and len(prefix):]
As a function:
def removePrefix(string, prefix):
    return string[len(prefix):] if string.startswith(prefix) else string


[source]
# ID Query