>>> s[0]
'n'
>>> s[18]
Traceback (most recent call last):
File "" , line 1, in
IndexError: string index out of range
>>> s[17]
'u'
>>> s[0:17]
'ni ming de hao yo'
>>> s[0:18]
'ni ming de hao you'
>>> s[18]
Traceback (most recent call last):
File "" , line 1, in
IndexError: string index out of range
>>>
s[18]越界了 但切片索引的时候为什么s[0:18]可以输出?
s[0:18]是取不到s[18]的,只会取到s[17],所以是可以的