很简单的问题,希望。所以,在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