Python - 检查单词是否在字符串中 [英] Python - Check If Word Is In A String
本文介绍了Python - 检查单词是否在字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Python v2,我想知道您是否可以判断一个单词是否在字符串中.
I'm working with Python v2, and I'm trying to find out if you can tell if a word is in a string.
我找到了一些关于识别单词是否在字符串中的信息 - 使用 .find,但是有没有办法做一个 IF 语句.我想要类似以下内容:
I have found some information about identifying if the word is in the string - using .find, but is there a way to do an IF statement. I would like to have something like the following:
if string.find(word):
print 'success'
感谢您的帮助.
推荐答案
有什么问题:
if word in mystring:
print 'success'
这篇关于Python - 检查单词是否在字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文