Méthode Python String startswith()
Exemple
Vérifiez si la chaîne commence par "Hello":
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Définition et utilisation
La startswith()
méthode renvoie True si la chaîne commence par la valeur spécifiée, sinon False.
Syntaxe
string.startswith(value, start, end)
Valeurs des paramètres
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 |
Plus d'exemples
Exemple
Vérifiez si les positions 7 à 20 commencent par les caractères "wel":
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)