Loading
0x60Lesson 7 of 10

Format text and parse input records

Use string methods and f-strings to build readable program output.

12 min 5-question quiz 1 code exercise
By the end of this lesson you can
  • Normalize text values and format a report line.

String methods such as strip, lower, and split help clean and parse text input. f-strings (f"...") make formatted output concise and readable, and are heavily used in logs and reports.

main.py
1name = "  Ada Lovelace  "
2city = "LONDON"
3clean_name = name.strip()
4clean_city = city.lower()
5print(f"{clean_name} ({clean_city})")
Output
Ada Lovelace (london)

Text processing is a core practical skill. Many scripts start by normalizing whitespace/case and then formatting result lines for humans or downstream tools.

Key takeaways

  • Normalize text values and format a report line.

  • Read the output to check what your program did.

  • Keep indentation consistent in Python blocks.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write Python

Write Python in the editor and run it against sample inputs. Python runs locally in your browser using a WebAssembly runtime.

Exercise 1

Normalize and report a user record

+25 XP

Read one line in format name,city and print name=<trimmed_name>; city=<lower_city>.

  • Trim and lowercase
  • Simple record
main.py
Loading editor…

Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…