Lesson 15 / 47

String Methods

Strings are immutable, but come with dozens of useful methods.

Everyday methods

Case, whitespace and search helpers cover most everyday text cleanup.

s = "  Hello Python  "
print(s.strip())
print(s.upper())
print(s.lower().strip().startswith("hello"))
print(s.replace("Python", "World"))

Strings are immutable

Every string method returns a new string — the original never changes. That's what "immutable" means.