如何在文本文档中定位文本块的位置

2024-04-19 22:09:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是在下面的例子中找到text2text1中的位置:

>>> text1='young lady  and lived in a firm so outside the cathedral close  it was somberly furnished  and full of dark young portraits'
>>> text2='the cathedral close it was sombrely furnished and full of dark'
>>> findtext2=text1.find(text2)
>>> findtext2
    -1

输出:-1。。。这意味着在text1中找不到text2

理想输出:42

有什么办法吗


Tags: andofthe目标closeitfulldark