String Python termina com () Método
Exemplo
Verifique se a string termina com um sinal de pontuação (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definição e uso
O endswith()
método retorna True se a string terminar com o valor especificado, caso contrário, False.
Sintaxe
string.endswith(value, start, end)
Valores de parâmetro
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 |
Mais exemplos
Exemplo
Verifique se a string termina com a frase "meu mundo.":
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Exemplo
Verifique se as posições 5 a 11 terminam com a frase "meu mundo".:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)