Editor

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 lesson

You 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 python
user_input = " HeLLo PyThOn "
# Clean up the input and print it

More string methods exercises

All Python exercises · 50 practice problems · Python Fundamentals quiz