Python String comienza con () Método
Ejemplo
Compruebe si la cadena comienza con "Hola":
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Definición y uso
El startswith()
método devuelve True si la cadena comienza con el valor especificado; de lo contrario, False.
Sintaxis
string.startswith(value, start, end)
Valores paramétricos
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 |
Más ejemplos
Ejemplo
Compruebe si la posición 7 a 20 comienza con los caracteres "wel":
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)