I am trying to check if a word has a trailing semicolon. I have the position of the word within a long string, and I want to check if the character at the position `start of word + length of word` is a `:`. It can be that the word is the last word in the string, and therefore trying to get the next char will raise an `IndexException`

I have three ideas:

**1) Check that we are not at the end of the string, and then check that it is not semicolon**

```
semicolon_pos = pos_word + len(word) # Possible position
if semicolon_pos < len(long_string) and long_string[semicolon_pos] == ':':
    # do something...
else:
    # do something else

```

Not what it is normally considered pythonic

**2) Try-except the semicolon extraction and the equality for the semicolon**

```
semicolon_pos = pos_word + len(word) # Possible position
try:
   if long_string[semicolon_pos] == ':':
      # Do something
   else:
      # do something else (which is the same as in the except clause)

except IndexError:
    # do something else

```

Looks a little bit weird, to extract and then nested. And I have to do a little trick to avoid the code duplication

**3) Try-except the semicolon extraction and an assertion to make sure it is a semicolon**

```
semicolon_pos = pos_word + len(word) # Possible position
try:
    assert long_string[semicolon_pos] == ':'
    # do something
except (IndexError, AssertionError):
    # do something else

```

Structure is flatter and it is easily read, but I have the feeling that is abusing exceptions usage.

What do the python folks say?
thanks in advance.