Python String termina con() Método
Ejemplo
Compruebe si la cadena termina con un signo de puntuación (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definición y uso
El endswith()
método devuelve True si la cadena termina con el valor especificado, de lo contrario, False.
Sintaxis
string.endswith(value, start, end)
Valores paramétricos
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 |
Más ejemplos
Ejemplo
Compruebe si la cadena termina con la frase "mi mundo":
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Ejemplo
Compruebe si la posición 5 a 11 termina con la frase "mi mundo".:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)