You know how to print strings and slice them with
[start:end]. Today we unlock the full toolkit: methods that let you split text apart, join it back together, search inside it, clean up extra spaces, and even reverse it. These are the moves a real Python developer uses every day.Splitting and joining
csv = "apple,banana,cherry"
parts = csv.split(",")
print(parts)
back_together = ".".join(["2024", "12", "5"])split(sep) cuts a string at every sep and returns a list. If you omit the argument, it splits on any whitespace. .join(iterable) does the reverse: it glues strings together with this string as the separator.Searching inside a string
word = "pythonic"
idx = word.find("thon")
is_prefix = word.startswith("pyt")
is_suffix = word.endswith("nic")find(sub) returns the index of sub or -1 if it is not there. .startswith(prefix) and .endswith(suffix) return a plain bool. They are cleaner than slicing when you only care about one end.Slicing with step, reversing, and stripping
s = "abcdefgh"
every_other = s[::2]
reversed_s = s[::-1]s[start:end:step] walks through s, taking one character every step. The special slice [::-1] is the idiomatic way to reverse a string. .strip() removes whitespace (and newlines) from both ends; use .lstrip() or .rstrip() for just one side.Replacing and checking content
msg = "hello world"
cleaned = msg.replace("world", "python")
"12345".isdigit()
"abcde".isalpha()