word[- 'nword[- 'oword[- 'plast character second-last character note that since - is the same as negative indices start from - in addition to indexingslicing is also supported while indexing is used to obtain individual charactersslicing allows you to obtain substringword[ : 'pyword[ : 'thocharacters from position (includedto (excludedcharacters from position (includedto (excludednote how the start is always includedand the end always excluded this makes sure that [:is[ :is always equal to sword[: word[ :'pythonword[: word[ :'pythonslice indices have useful defaultsan omitted first index defaults to zeroan omitted second index defaults to the size of the string being sliced word[: 'pyword[ :'onword[- :'oncharacter from the beginning to position (excludedcharacters from position (includedto the end characters from the second-last (includedto the end one way to remember how slices work is to think of the indices as pointing between characterswith the left edge of the first character numbered then the right edge of the last character of string of characters has index nfor example+---+---+---+---+---+--- +---+---+---+---+---+--- - - - - - - the first row of numbers gives the position of the indices in the stringthe second row gives the corresponding negative indices the slice from to consists of all characters between the edges labeled and jrespectively for non-negative indicesthe length of slice is the difference of the indicesif both are within bounds for examplethe length of word[ : is attempting to use an index that is too large will result in an errorword[ the word only has characters traceback (most recent call last)file ""line in indexerrorstring index out of range using python as calculator