Hinzufügen von Schlüsselwortargumenten
Vorhin hast du eine benutzerdefinierte Funktion zum Bereinigen von Text erstellt, die hier noch mal aufgeführt ist:
# 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
Jetzt änderst du sie so, dass sie verschiedene Standardwerte für Schlüsselwortargumente akzeptiert.
Diese Übung ist Teil des Kurses
Entwicklung mit Python für Fortgeschrittene
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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