This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatique:python [2024/12/10 20:57] – yahiko | informatique:python [2024/12/13 21:11] (current) – yahiko | ||
|---|---|---|---|
| Line 85: | Line 85: | ||
| ===== Trouver la longueur d'une chaîne de caractères ===== | ===== Trouver la longueur d'une chaîne de caractères ===== | ||
| <code python> | <code python> | ||
| - | string = 'C'est vachement long quand même cette affaire dis donc.' | + | string = "C'est vachement long quand même cette affaire dis donc." |
| print(len(string)) | print(len(string)) | ||
| </ | </ | ||
| + | Va retourner '' | ||
| + | |||
| + | ===== Le dernier caractère d'une chaîne ===== | ||
| + | <code python> | ||
| + | print(" | ||
| + | </ | ||
| + | Va retourner '' | ||
| ===== Fonctions ===== | ===== Fonctions ===== | ||
| Line 133: | Line 140: | ||
| print(shorten(chaine)) | print(shorten(chaine)) | ||
| </ | </ | ||
| + | |||
| + | === Faire un truc si le dernier caractère d'une chaîne est quelque chose === | ||
| + | Je ne sais pas, un '' | ||
| + | <code python> | ||
| + | def DashCheck(check): | ||
| + | if check == ' | ||
| + | dash = str(" | ||
| + | else: | ||
| + | dash = str(" | ||
| + | return dash | ||
| + | |||
| + | print(DashCheck(" | ||
| + | </ | ||
| + | Va retourner '' | ||
| + | |||
| + | Et si on veut supprimer ce dernier '' | ||
| + | <code python> | ||
| + | def DashCheck(check): | ||
| + | # On vérifie le dernier caractère de la chaîne | ||
| + | if check[-1] == ' | ||
| + | # Si " | ||
| + | dash = check[:-1] | ||
| + | return dash | ||
| + | else: | ||
| + | return check | ||
| + | </ | ||
| + | |||