我的目标是在下面的例子中找到text2
在text1
中的位置:
>>> 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
有什么办法吗
您使用的方法是正确的,
find
。只是“sombrely”在text1
中拼写不正确,反之亦然(无论你认为哪个对你有效)。同时检查text1
和text2
中的空间不匹配相关问题 更多 >
编程相关推荐