Python String finisce con() Metodo
Esempio
Controlla se la stringa termina con un segno di punteggiatura (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definizione e utilizzo
Il endswith()
metodo restituisce True se la stringa termina con il valore specificato, altrimenti False.
Sintassi
string.endswith(value, start, end)
Valori dei parametri
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 |
Altri esempi
Esempio
Controlla se la stringa termina con la frase "il mio mondo".:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Esempio
Controlla se le posizioni da 5 a 11 terminano con la frase "il mio mondo".:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)