很簡單的問題,希望。所以,在Python中可以分割使用指標如下字符串:如何以編程方式分割python字符串?
>>> a="abcdefg"
>>> print a[2:4]
cd
但你如何做到這一點,如果指數是根據變量?例如。
>>> j=2
>>> h=4
>>> print a[j,h]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: string indices must be integers
使用冒號而不是逗號......就像使用數字索引一樣。 :o) – 2010-05-27 11:15:32