Zed Fang
Zed Fang

Reputation: 883

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):
    start_str=string.find('<')
    if start_str==-1:
        return None,0

    end_str=string.find('>',start_str)
    next_start_str=string.find('<',end_str)

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

    word=string[end_str+1,next_start_str]
    return word,next_start_str



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

Upvotes: 0

Views: 96

Answers (1)

Wondercricket
Wondercricket

Reputation: 7872

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]

Upvotes: 3

Related Questions