以下是一个使用 Python 实现的简单文档内容查询程序示例,它可以查找文档中指定字符串的索引: ```python def search_document(document, target): indices = [] start = 0 while True: index = document.find(target, start) if index == -1: break indices.append(index) start = index + 1 return indices document = "it is not the critic who counts, not the man who points out how the strong man stumbles, the doer of deeds could have done them better. the credit belongs to the man who is actually in the are 'ns, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, and comes short again and again ;because there is not effort without error and shortcoming; but who does actually strive to do the deeds; who knows the great enthusiasms, the grea" target = "man" print(search_document(document, target)) ``` 在上述示例中,定义了一个 `search_document` 函数,它接受文档内容和要查找的目标字符串作为参数,并返回目标字符串在文档中的所有索引位置。 [2024-10-22 15:41:34 | AI写代码神器 | 259点数解答]