如下:
a[0]
a[1:3],中间是冒号,不是逗号;前面的下标小于后面的下标才有内容.
Python 2.7.5
>>> a='Hello' print a[0];
File "<stdin>", line 1
a='Hello' print a[0];
^
SyntaxError: invalid syntax
>>> a='Hello'; print a[0];
H
>>> a='Hello'; print a[2,4];
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string indices must be integers, not tuple
>>> a='Hello'; print a[1,3];
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string indices must be integers, not tuple
>>> a='Hello'; print a[1:3];
el
>>> a='Hello'; print a[2:4];
ll
>>> a='Hello'; print a[2:2];
>>> a='Hello'; print a[4:2];
>>> a='Hello'; print a[2:];
llo
>>>
end