任何人都可以建議一種使用python在段落中搜索句子的方法。一個段落可以有20個句子。我想要一個特定的句子在段落中是否存在
key="I want a particular"
parag="what is there to know about.Can anyone suggest a way to search for a sentence in a paragraph with python. A paragraph can have 20 sentences. I want a particular sentense is there in paragraph or not"
我想回傳真或假,如果真需要替換為“在段落中找到位置”。
uj5u.com熱心網友回復:
key in parag
會告訴你你的鑰匙是否在段落中。您還可以使用 index 在段落中查找鍵的位置。
index = parag.index(key)
如果 key 不在 parag 中,那么這將引發 ValueError,但如果是,那么您將取回 key 在段落中開始的索引。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/437198.html
上一篇:如何使用模式從字串中獲取特定資料
