Python - Slicing
📖 Read the lesson
Code Life
By Pierre Marsaa
Introduction to String Slicing
String slicing is a way to extract a part of a string (a substring). It's like cutting a piece from a string.
The basic syntax for slicing is: string[start:end]
Where:
- start is the index where the slice starts (inclusive)
- end is the index where the slice ends (exclusive)
↗️
Loading editor...
↶
▶️ Run
↷
Remember that in Python, string indices start at 0, not 1. So the first character is at index 0, the second at index 1, and so on.
Important Note
The end index is NOT included in the slice. So [0:4] gives you characters at positions 0, 1, 2, and 3, but not 4.
Verify