Description de la méthode startswith() Python
La méthode startswith() vérifie si la chaîne commence par une occurrence 'str' fournie en paramètre, limitant éventuellement la correspondance avec les indices donnés beg et end.
|
1 |
Syntaxe de la méthode startswith() |
|
1 |
string.startswith(str, beg = 0,end = len(string)) |
Paramètres de la méthode startswith()
- str: occurrence à vérifier.
- beg: paramètre facultatif pour définir l'index de début de la limite correspondante.
- end : paramètre facultatif pour définir l'index de début de la limite correspondante.
Valeur de retour de la méthode startswith()
Cette méthode renvoie True si la chaîne correspondante est trouvée, False sinon.
Exemple d'usage de la méthode startwidth()
|
1 2 3 4 5 |
string = "Python programming" print (string.startswith( 'Pyt' )) # affiche: True print (string.startswith( 'Pyt', 3 )) # affiche: False print (string.startswith( 'prog', 7, 11 )) # affiche: True print (string.startswith( 'prog', 3, 12 )) # affiche: False |
Younes Derfoufi
CRMEF OUJDA
![[App intégrée] 2025 Upgraded Vidéoprojecteur 1920 * 1080P FHD 4K Mini Projecteur Portable Dual Contrôle avec Souris Android TV WiFi 6 BT5.2 180° Rotation Compatible avec HDMI/TV Stick/USB](https://www.tresfacile.net/wp-content/uploads/2025/12/Videoprojecteur-1920-1080P-FHD-4K-Mini-Projecteur-Portable-Dual-Control-250x236.png)


1 thought on “La méthode de chaine de caractères startswith() Python”