Metoda Python String endswith().
Příklad
Zkontrolujte, zda řetězec končí interpunkčním znaménkem (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definice a použití
Metoda endswith()
vrátí True, pokud řetězec končí zadanou hodnotou, jinak False.
Syntax
string.endswith(value, start, end)
Hodnoty parametrů
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 |
Další příklady
Příklad
Zkontrolujte, zda řetězec končí frází „můj svět.“:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Příklad
Zkontrolujte, zda pozice 5 až 11 končí frází „můj svět.“:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)