Python String kończy się metodą ()
Przykład
Sprawdź, czy ciąg kończy się znakiem interpunkcyjnym (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definicja i użycie
Metoda endswith()
zwraca True, jeśli ciąg kończy się określoną wartością, w przeciwnym razie False.
Składnia
string.endswith(value, start, end)
Wartości parametrów
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 |
Więcej przykładów
Przykład
Sprawdź, czy ciąg kończy się frazą „mój świat.”:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Przykład
Sprawdź, czy pozycje od 5 do 11 kończy się frazą „mój świat.”:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)