Python -Zeichenfolge endet mit () Methode
Beispiel
Überprüfen Sie, ob die Zeichenfolge mit einem Satzzeichen (.) endet:
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definition und Verwendung
Die endswith()
Methode gibt True zurück, wenn der String mit dem angegebenen Wert endet, andernfalls False.
Syntax
string.endswith(value, start, end)
Parameterwerte
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 |
Mehr Beispiele
Beispiel
Überprüfen Sie, ob die Zeichenfolge mit der Phrase „my world.“ endet:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Beispiel
Überprüfen Sie, ob die Positionen 5 bis 11 mit dem Ausdruck „my world.“ enden:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)