Color theme
0 day streak0 XPP1
PythonLearn mode
MISSION 1 OF 1

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 / 2 challenges
LEARN THE CONCEPT

Understand it, then try it.

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.

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.

Track the values line by line. Predict the result before running this example in your own editor.