Skip to content

Note 07: Strings

Strings store text. They support indexing, slicing, and traversal.

word = "python"
print(word[0])
print(word[-1])
print(word[1:4])

Useful Patterns

  • Count specific characters.
  • Search for a character or substring.
  • Build a cleaned-up result one character at a time.
vowels = 0
for letter in word:
    if letter in "aeiou":
        vowels += 1

Strings are immutable, so methods and slicing create new values rather than changing the original string in place.