CommencerCommencer gratuitement

Ajouter un argument de type mot-clé

Précédemment, vous avez développé une fonction personnalisée pour nettoyer le texte, comme indiqué ici :

# Create the clean_string function
def clean_string(text):

      # Replace spaces with underscores
      no_spaces = text.replace(" ", "_")

      # Convert to lowercase
      clean_text = no_spaces.lower()

      # Display the final text as an output
      return clean_text

Vous allez maintenant la modifier pour qu'elle prenne par défaut différents arguments par mots-clés.

Cet exercice fait partie du cours

Python intermédiaire pour les développeurs

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Define clean_text
____ ____(____, ____):
  if lower == False:
    clean_text = text.replace(" ", "_")
    return clean_text
  else:
    clean_text = text.replace(" ", "_")
    clean_text = clean_text.lower()
    return clean_text
Modifier et exécuter le code