String Methods & f-strings
Python · Beginner
Definition
Python strings have built-in methods like split, join, strip, replace and upper, and f-strings format values.
Text processing is part of nearly every program.
Diagram
Flowchart
Example: Common methods
s = ' hack the future '
w = s.strip().split()
print('-'.join(w).upper(), f'{len(w)} words')Output: HACK-THE-FUTURE 3 words
Key points
- f'{x:.2f}' formats decimals
- str.isdigit() checks digits
Interview questions
split() vs split(' ')?
split() handles any whitespace and drops empties; split(' ') keeps empty strings.