Método Python String startswith()
Exemplo
Verifique se a string começa com "Hello":
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Definição e uso
O startswith()
método retorna True se a string começar com o valor especificado, caso contrário, False.
Sintaxe
string.startswith(value, start, end)
Valores de parâmetro
Parameter | Description |
---|---|
value | Required. The value to check if the string starts 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 posição 7 a 20 começa com os caracteres "wel":
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)