Slicing strings

s[start:stop] gives the characters from start up to, but not including, stop. Leave out start to begin at 0, or stop to run to the end.

A third number is the step: s[::2] takes every second character, and s[::-1] reverses the string. That is the quickest palindrome check: s == s[::-1].

Slices never raise. s[2:100] stops at the end, and s[5:2] is just "". Indexing a single position past the end still raises IndexError.

The same slicing works on lists and tuples. A slice is always a copy, so s[:] on a list gives a new list.

Run it, then try word[-3:] and word[1:-1].