✦ Python Foundations Working with Data module

Concept 19 · String Methods

Clean up text.
Keep the original safe.

Text is a sequence of characters. Methods such as lower(), upper(), strip(), replace(), split(), and join() help real programs clean and organize user input.

01 Learn02 Try03 Predict

String methods return new text instead of changing the original string.

Text is a sequence of characters. Methods such as lower(), upper(), strip(), replace(), split(), and join() help real programs clean and organize user input.

message = "  Hello Python  "

cleaned = message.strip().lower()
print(cleaned)

words = "Ana,Marko,Jelena".split(",")
print(words)

strip() and lower() produce a new cleaned string. split() turns comma-separated text into a list of words.

hello python ['Ana', 'Marko', 'Jelena']

Change one value, then explain how the resulting data changes.

↳

Keep this in mind: Follow each data operation in order before predicting the result.

Try it
name = "  ANA  "

cleaned = name.strip().lower()
print(cleaned)
print(name)

words = "Ana,Marko,Jelena".split(",")
print(" | ".join(words))
# Try upper(), replace(), or different text

Run the example, then change one value and observe the result.

Python Playground

Loading Python runtime…

Edit the example and run it in your browser.

string_methods.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Read each data operation before choosing an answer.

message = "  PyThOn tutor  "
cleaned = message.strip().lower().replace(" ", "-")
print(cleaned)
print(message)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Ask Sloby about string methods

Describe what feels unclear and Sloby will guide your reasoning.

Hi! I'm Sloby. Let's clean and transform Python text together.

What will this program print, and why does original keep its spaces and capitalization? Explain strip(), lower(), split(), and join().

original = "  Ana, Marko  "
cleaned = original.strip().lower()
parts = cleaned.split(", ")

print(original)
print(parts)
print("-".join(parts))
Python AI Tutor · Learn by understanding, not just by running code.