Syncing account progress…

Back

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

Working with text

  1. Compare the original text with the cleaned result.
  2. Count the characters before running the example.

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.

Practice