Color theme
0 day streak0 XPP1
PythonQuiz mode
MISSION 1 OF 3

Clean an imported filename

0 XP earned
Python track: BeginnerMission: BeginnerWhitespace trimmingString methodsImmutability
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.

x
0 / 6 challenges
KNOWLEDGE CHECK

Predict the result.

What filename is printed, with no surrounding whitespace?

mission.py
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.

Choose your answer+25 XP on first completion