【发布时间】:2021-04-04 02:34:51
【问题描述】:
如何判断一个单词是否在字符串中?
- 单词不是子字符串。
- 我不想使用正则表达式。
仅使用in 是不够的...
类似:
>>> wordSearch('sea', 'Do seahorses live in reefs?')
False
>>> wordSearch('sea', 'Seahorses live in the open sea.')
True
- 注 1:“sea”和“seahorses”是不同的词。
- 注意 2:绑定标点会引起麻烦。
- 注3:How do I check if a sentence contains a certain word in Python and then perform an action?中的问题 不是同一个问题。
【问题讨论】:
-
@Kevin,不,它没有。不同的问题,不同的问题,不同的答案。
-
你为什么在我标记为与当时重复的其他问题之一上发布相同的答案? stackoverflow.com/a/65453803/5517088
-
我在那里发布了我的解决方案,因为接受的解决方案至少是不完整的。检查一下。
标签: python python-3.x string