Python String inizia con() Metodo
Esempio
Controlla se la stringa inizia con "Hello":
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Definizione e utilizzo
Il startswith()
metodo restituisce True se la stringa inizia con il valore specificato, altrimenti False.
Sintassi
string.startswith(value, start, end)
Valori dei parametri
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 |
Altri esempi
Esempio
Controlla se la posizione da 7 a 20 inizia con i caratteri "wel":
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)