Strings and Text

8. Strings and Text#

Strings are sequences of characters, so many sequence ideas from lists and tuples also apply to text.

  • Strings as immutable sequences

  • String methods for cleaning and transforming text

  • Regular expressions for pattern matching

  • Dictionaries and counters for text analysis

  • Random text and Markov-style generation

Video

This overview introduces strings, string operations, and common string methods for working with text.

Learning Goals

By the end of this chapter, you will be able to:

  1. Create, index, slice, and compare strings

  2. Use string methods to clean, search, split, join, and format text

  3. Use regular expressions to find and replace text patterns

  4. Count words and summarize text with dictionaries and Counter

  5. Generate simple random text from word relationships

Chapter Flow

Chapter Overview Slides