Site Tools


informatique:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
informatique:python [2024/12/11 22:47] yahikoinformatique:python [2024/12/13 21:11] (current) yahiko
Line 144: Line 144:
 Je ne sais pas, un ''-'' par exemple. Je ne sais pas, un ''-'' par exemple.
 <code python> <code python>
-def DashCheck(dash): +def DashCheck(check): 
- if dash == '-': + if check == '-': 
- IsDash = str("Prout")+ dash = str("Prout")
  else:  else:
- IsDash = str("Pas prout"+ dash = str("Pas prout"
- return IsDash+ return dash
  
 print(DashCheck("Lalalal-")) print(DashCheck("Lalalal-"))
 </code> </code>
 Va retourner ''Prout''. Va retourner ''Prout''.
 +
 +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 "-" alors on le supprime
 + dash = check[:-1]
 + return dash
 + else:
 + return check
 +</code>
  
  
  
  
informatique/python.1733957250.txt.gz · Last modified: 2024/12/11 22:47 by yahiko