2024-09-27 22:36:19 发布
网友
所以我在做一个列表的for循环。每一个字符串,我都想。查找,但不是。为一个字符串找到一个项,我要检查该字符串中的任何内容。在
例如。在
checkfor = ['this','that','or the other']
那就去吧
在字符串。查找(检查)或者别的什么,所以我想这样做:
你可以尝试使用列表理解来完成这项工作。在
occurrences = [i for i, x in enumerate(email) if x =='this']
I want to check that string for anything in my list
Python对此有in。在
in
for s in checkfor: if s in email: # do action
使用in子句:
If checkfor not in email: do_some_thing()
你可以尝试使用列表理解来完成这项工作。在
Python对此有
in
。在使用
in
子句:相关问题 更多 >
编程相关推荐