s2 = "fast and furious series from one to seven"
print "s2.index('e', 50, 0) : ", s2.index('e', 50, 0)
错误:
print "s2.index('e', 50, 0) : ", s2.index('e', 50, 0)
ValueError: substring not found
答案 0 :(得分:0)
你要求Python在空切片中找到e
;第二个和第三个参数是 start 和 end 索引。 s2[50:0]
是一个空字符串:
>>> s2 = "fast and furious series from one to seven"
>>> s2[50:0]
''
如果您想通过搜索结尾查找文字,请使用str.rindex()
function:
>>> s2.rindex('e')
39