例如我有文字:
“约翰起床了。约翰去看电影了。约翰洗了手。”
现在我想先找到“John”并做一些事情,然后我想找到下一个“John”并做一些事情,所以我需要使用像findNext()
这样的东西,考虑到实际位置,所以不是从头找,而是从实际位置找。
最佳答案
查找方法有一个开始
参数:
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
关于python - 在 Python 中是否类似于字符串中的方法 findNext()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31228467/