Python · Beginner · 10 min
Working with text
Clean up text, change its case, and count characters.
Clean and change text
A method is called after a dot. strip() removes whitespace from both ends. lower() returns lowercase text. These methods return new strings; assign the result to keep it.
label = " HELLO "
clean = label.strip()
print(clean.lower())Output
hello
Count characters
len() returns the number of characters in this example. Spaces count too. upper() returns uppercase text.
word = "hello"
print(len(word))
print(word.upper())Output
5 HELLO
Try it yourself
Code runs on this device. When you are signed in, drafts sync to your account.
Clean a label
Clean raw with strip() and lower(). Store the result in label and display it. The output must be python.
You can call lower() on the result of raw.strip().
Working with text
- Compare the original text with the cleaned result.
- Count the characters before running the example.