str.startswith() Se começa com uma string
Última atualização: 2026-09-22
str.startswith() Se começa com uma string
str.startswith(prefix[, start[, end]]) verifica se a string começa com prefix.
| Categoria | Métodos de string |
|---|---|
| Tipo | Método de tipo interno |
| Versão do Python | all |
📝 Sintaxe
str.startswith(prefix[, start[, end]])
⚙️ Parâmetros
| prefix Obrigatório | The prefix to check; a string or a tuple of strings. |
|---|---|
| start Opcional | Start index of the range (inclusive); None means the beginning.(Padrão:None) |
| end Opcional | End index of the range (exclusive); None means the end.(Padrão:None) |
Retorno:bool. True if the string starts with prefix within the range.
Modifica o original:Não (retorna um novo objeto)
▶ Exemplo
Edite o código, clique em Executar e veja o resultado no painel de saída:
Saída:
True
False
💡 Casos relacionados
Mais estudos de caso em breve — aguarde.
❓ Perguntas frequentes
QComo verificar múltiplos prefixos?
APasse uma tupla: 'hello.py'.startswith(('a', 'he')) retorna True. O prefixo pode ser uma string ou uma tupla de strings.
QÉ sensível a maiúsculas/minúsculas?
ASim. 'Http'.startswith('http') é False; você pode aplicar lower() antes.
QComo são usados os parâmetros start/end?
AEles delimitam o intervalo de verificação (fechado à esquerda, aberto à direita): 'hello'.startswith('el', 1) verifica o substring 'ello' a partir do índice 1 e retorna True.