A string behaves like a sequence of characters. We can index it, slice it, scan it, and use many of the same patterns we use with arrays.

Strings are often immutable

In Python, changing one character creates a new string. Repeatedly adding characters can therefore copy more data than expected. Collecting pieces and joining once is often clearer.

  • Normalize case when capitalization should not matter.
  • Decide how spaces and punctuation should behave.
  • Remember that a visible symbol can be more complex than one simple byte.

Transform with one pass

Keep only lowercase lettersPython
def clean_text(text):
    letters = []

    for character in text.lower():
        if character.isalpha():
            letters.append(character)

    return "".join(letters)

print(clean_text("Hello, World!"))
# helloworld

Before solving a text problem, define what counts as equal. Should A equal a? Should spaces count? Clear rules prevent surprising answers.

Frequency counting, two pointers, and sliding windows all work naturally on strings because characters have an order.

Your tiny challenge

Clean the phrase Never odd or even, then use two pointers to check whether it is a palindrome.