Clean Up User Input
Beginner · Write the code · from Every Python String Method Explained with Examples
From the lesson: Every Python String Method Explained with Examples
Strings in Python come with a toolbox of built-in methods. These methods let you change case, remove extra spaces, search for words, split text apart, and much more.
Read the lessonYou have a messy string stored in the variable user_input. It has extra spaces on both sides and random uppercase letters.
Clean it up by:
1. Removing whitespace from both ends
2. Converting to all lowercase
Print the cleaned result. The output should be:
hello pythonuser_input = " HeLLo PyThOn "
# Clean up the input and print it
More string methods exercises
- Count Word OccurrencesBeginner
- Replace All OccurrencesBeginner
- Split a CSV LineBeginner
- Fix the Bug -- find() vs index()Beginner
- Validate a UsernameBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz