Use assert for control flow
问题 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