Python · Lesson 3 of 9
Strings
f-strings, common string methods, indexing and slicing.
Strings hold text. The most useful tool is the f-string: put f before the quotes and write variables inside { }.
Handy methods
.upper(), .lower(), .title(), .strip() (remove spaces at both ends), .replace(a, b), .split(",") (text → list) and ", ".join(list) (list → text). Methods return a new string; the original is unchanged.
Indexing and slicing
Each character has a position starting at 0. s[0] is the first, s[-1] the last, and s[0:4] takes characters 0 to 3. len(s) gives the length.
Try it yourself
Press Run to see the output.
Edit and press Run (or Ctrl/⌘ + Enter). Python runs in your browser — the first run downloads the Python engine and takes a few seconds.
Key points
- f"...{value}..." formats text cleanly.
- String methods return new strings.
- Indexes start at 0; negative indexes count from the end.
Quick check
What is "Kerala"[-1]?
Index -1 is the last character, which is "a".
Practice task
Given email = " Anu.Kumar@Example.COM ", print it trimmed and in lower case, then print only the part before the @.
Interview corner
How do you reverse a string in Python?
Use a slice with step -1: text[::-1]. It returns a new reversed string.
Why are strings immutable and what does that mean in practice?
You cannot change a character in place (s[0] = 'x' fails). Every change produces a new string, which makes strings safe to share and usable as dictionary keys.
Further reading
Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.
Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.