String Methods

split, join, strip, replace, find

Interview Relevant: Essential string manipulation

String Methods

Common ways to manipulate strings.

Code Examples

Useful string methods.

python
1s = "  Hello, World!  "
2s.strip()       # "Hello, World!"
3s.lower()       # "  hello, world!  "
4s.upper()       # "  HELLO, WORLD!  "
5s.replace("!", "?")
6s.split(",")    # ["  Hello", " World!  "]
7", ".join(["A", "B"]) # "A, B"
8s.find("World") # Index (or -1)

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In