L1·Foundations

🔤Strings & f-strings

Immutable text sequences and rich formatting.

strformatf-stringslicing

§ 1Immutable sequences

Strings are sequences of Unicode code points. You can slice them but not mutate in place.

§ 2f-strings

f"..." evaluates expressions inside {}. Supports formatting mini-language: {value:.2f}, {n:>10}, {n:,}.

§ 3Common methods

.upper() .lower() .strip() .split() .replace() .startswith() .endswith() .join().

Example

1name = "ada"
2age = 36
3print(f"{name.title()} is {age} years old")
4print(f"pi ≈ {3.14159:.2f}")
5print("-".join(["a", "b", "c"]))

Try it live · Python runs in your browser

Loading playground…

Checkpoint quiz

Question 1 / 3
What is 'python'[1:4]?