Slicing selects a range from a Python string or list with [start:stop]. Indexing starts at 0, start defaults to the beginning, stop defaults to the end, and stop is excluded. section 2.1.7 section 3.3.4
Use slices to:
- Take the first characters or elements with word[:3] or items[:2]. section 2.1.7 section 3.3.4
- Take everything after a position with word[3:] or items[2:]. section 2.1.7 section 3.3.4
- Count backward with negative indexes, such as word[-1] for the final character. section 2.1.7
- Safely request ranges beyond a list’s length; items[10:] returns []. section 3.3.4
Rebuilding an immutable string
Strings cannot be changed by assigning to one position. Build a replacement instead: with i = 13, text[:i] gives the part before the position and text[i+1:] gives the part after it; combine them with a new character: text = text[:i] + new_char + text[i+1:]. section 10.3.1
Extracting and shuffling a word’s middle
For word = 'worry', word[1:-1] produces 'orr'. Convert that slice to a list before calling random.shuffle(), because strings cannot be modified in place; then combine the first, shuffled middle, and last parts. section 16.1.4
Inspect the REPL examples for zero-based indexing, negative indexes, omitted boundaries, and the non-inclusive stop position. section 2.1.7



















