在 Python 中是否类似于字符串中的 findNext() 方法?

use*_*552 1 python string parsing find

例如我有文字:

“约翰起床了。约翰去看电影了。约翰洗手了。”

现在我想找到第一个“约翰”并做一些事情,然后我想去下一个“约翰”并做一些事情,所以我需要使用类似的东西findNext(),它考虑了实际位置,所以它不会从一开始,而是从实际位置。

Dan*_*iel 5

find-Method 有一个start-argument:

text = "John got up. John went to the cinema. John washed his hand."
pos = -1 
while True:
    pos = text.find('John', pos + 1)
    if pos == -1:
        break
    do_something
Run Code Online (Sandbox Code Playgroud)