Question

Comment supprimer un préfixe ou une sous-chaîne en début de chaîne de caractères en Python ?


Annonce
Ad

Réponse

output = string[string.startswith(prefix) and len(prefix):]
Sous forme de fonction :
def removePrefix(string, prefix):
    return string[len(prefix):] if string.startswith(prefix) else string


[source]
# ID Query