Clean an imported filename
Before you start this beginner track
Variables, strings, and basic lists. Build up to dictionary counting.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Predict the result.
What filename is printed, with no surrounding whitespace?
raw_name = " guide.MD \n"trimmed_name = raw_name.strip()filename = trimmed_name.lower()print(filename)Run each standalone script with Python 3.8+. File names and log entries are in-memory sample text; no files, packages, or input are required.
Review the lesson
Imported text can contain unwanted whitespace around a useful value. strip returns a string with whitespace removed from both ends, while leaving spaces inside the name alone. lower returns a lowercase version. Strings are immutable, so each result is assigned to a variable before the cleaned filename is printed.