Level 1
0 / 100 XP

Section 7 overview

Text is everywhere in real programs — names, file paths, user input, log lines, search terms. Python calls a piece of text a string, and it gives you a rich toolkit for cleaning, inspecting, and reshaping that text.

In this section you'll go from "a string is just some letters" to confidently slicing it apart, searching inside it, transforming its case, and splitting it into pieces.

What you'll learn

  • String methods — clean and transform text with .strip(), .lower(), .upper(), .replace()
  • Slicing and in — pull out parts of a string by position and check whether text contains something
  • Split, join, and search — break text into pieces, glue pieces back together, and test how text begins or ends
  • f-strings — drop variables straight into text to build clean, readable output
Python
name = " Ada Lovelace " clean = name.strip() print(clean.upper()) # ADA LOVELACE print(clean.split()) # ['Ada', 'Lovelace'] print(f"Hello, {clean}!") # Hello, Ada Lovelace!

By the end you'll be able to take messy raw text and turn it into exactly the output you want — a skill you'll use in nearly every program.

Key takeaways

  • A string is a piece of text, and Python gives you many tools to work with it.
  • This section covers string methods, slicing, in, split/join, searching, and f-strings.
  • String methods always return a new string — the original never changes.