我正在检查列表中的值是否存在于以下句子中:
rich = ["Businessman","Robber","Politician"]
poor = ["Programmer","Engineer","Doctor"]
whoAmI = "I am an Engineer"
if rich.*MISSING_HERE* in whoAmI:
print "You are RICH"
else :
print "You are POOR"
如果您查看带有If语句的行,我将检查rich
中是否有任何元素在whoAmI
中可用。我怎么检查这个?你知道吗
使用
any()
方法-我们可以使用Python库的
re
或regex模块来搜索字符串中的单词。我们将使用simpleforloop(注:时间复杂度:O(n))我们使用Python内置函数
quit()
,以防止相同的输出多次显示。你知道吗试试for else循环
相关问题 更多 >
编程相关推荐