Python String Methods and Slicing, Explained
s = "hello"; s.upper(); print(s) still prints "hello" — strings are
immutable, and that one surprise underlies almost every method in
Python's string toolkit. A complete walkthrough of the operations
you'll reach for in almost every piece of real text processing:
Strings are immutable - every "modifying" method returns a NEW
string, the original is untouched. Forgetting to reassign
(s = s.upper(), not just s.upper()) is one of the most common first
mistakes
Splitting and joining - .split(sep) keeps empty pieces, bare
.split() collapses whitespace and discards them; .join() is called
on the separator, the reverse of what most people guess
Stripping, replacing, and case - .strip() only touches the ends, not
the middle; .replace() swaps every occurrence by default
Checking content - .isdigit(), .isalpha(), and .startswith()/
.endswith() accepting a tuple of options
Slicing with s[start:stop:step] - negative indexing, stop is always
exclusive, and s[::-1] as the idiomatic way to reverse a string
Full lesson (with more depth, a quiz, and flashcards):
https://devreps.mohamedyounes.dev/lib...
DevReps is a free training log for software engineering - 426+ lessons
across 23 domains, spaced-repetition flashcards, and a built-in AI
tutor. New reps posted weekly.
#python #coding #softwareengineering