The word Hello
contains 5 characters.
>>> x = 'Hello'
>>>
>>> len(x)
5
>>>
x[5]
will produce an error as Python number is started from 0. I can understand this.
>>> x[5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>>
>>> x[0]
'H'
>>>
And last charactor is at x[4]
>>> x[4]
'o'
>>>
However, when I try a range which is from x[0:4]
, the last letter is not there.
>>> x[0:4]
'Hell'
>>>
May I know why?