Zed Fang Zed Fang - 10 months ago 50
Python Question

This code keeps giving me: string indices must be integers

I keep getting a TypeError: string indices must be integers. Not sure how to correct this.

def get_next_target(string):
if start_str==-1:
return None,0


if next_start_str==-1:
return string[end_str+1:]

return word,next_start_str

print (get_next_target('<h1>Title <>'))

Answer Source

You are trying to use a , for string slicing, which is causing this to become a tuple. You need to replace the , with a :

word=string[end_str + 1:next_start_str]