← Python Programming learning path
Python Programming · Module 6 of 10

Strings

Work with text: indexing, slicing and useful string methods.

📖 Key ideas

  1. Strings are text in quotes: "hello" or 'hello'.
  2. Indexing starts at 0: s[0] is the first character; s[-1] is the last.
  3. Slicing s[1:4] takes characters 1 to 3.
  4. Methods: upper(), lower(), strip(), replace(), split(), find().
  5. Strings are immutable: methods return new strings.
💡 Real-life example: A string is like a train of letters: each coach has a number starting from 0.
s[0]First character
s[-1]Last character
split()Breaks text into a list
strip()Removes spaces at both ends