作者:州徐国中 | 来源:互联网 | 2023-10-13 09:02
Suppose I create a string:
假设我创建了一个字符串:
>>> S = "spam"
Now I index it as follows:
现在我将其索引如下:
>>> S[0][0][0][0][0]
I get output as:
我输出为:
>>> 's'
But when i index it as:
但当我将其索引为:
>>> S[1][1][1][1][1]
I get output as:
我输出为:
Traceback (most recent call last):
File "", line 1, in
L[1][1][1][1][1]
IndexError: string index out of range
Why is the output not 'p'?
为什么输出不是'p'?
Why also it is working for S[0][0] or S[0][0][0] or S[0][0][0][0] and not for S[1][1] or S[1][1][1] or S[1][1][1][1]?
为什么它也适用于S [0] [0]或S [0] [0] [0]或S [0] [0] [0] [0]而不适用于S [1] [1]或S [1] [1] [1]或S [1] [1] [1] [1]?
3 个解决方案