Méthode Python String endswith()
Exemple
Vérifiez si la chaîne se termine par un signe de ponctuation (.) :
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Définition et utilisation
La endswith()
méthode renvoie True si la chaîne se termine par la valeur spécifiée, sinon False.
Syntaxe
string.endswith(value, start, end)
Valeurs des paramètres
Parameter | Description |
---|---|
value | Required. The value to check if the string ends with |
start | Optional. An Integer specifying at which position to start the search |
end | Optional. An Integer specifying at which position to end the search |
Plus d'exemples
Exemple
Vérifiez si la chaîne se termine par la phrase "mon monde." :
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Exemple
Vérifiez si les positions 5 à 11 se terminent par la phrase "mon monde." :
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)