← Python Programming learning pathPython Programming · Module 6 of 10
Strings
Work with text: indexing, slicing and useful string methods.
📖 Key ideas
- Strings are text in quotes: "hello" or 'hello'.
- Indexing starts at 0: s[0] is the first character; s[-1] is the last.
- Slicing s[1:4] takes characters 1 to 3.
- Methods: upper(), lower(), strip(), replace(), split(), find().
- 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