Because of the syntax of string slicing, s[m:n]
, the number n-m
is always the length of the substring. In other words, to return r
characters starting at index m
, use s[m:m+r]
. For example,
>>> s = 'whitechocolatespaceegg'
>>> s[:5]
'white'
>>> s[5:14]
'chocolate'
>>> s[14:19]
'space'
>>> s[19:]
'egg'