我是一个Python新手,但我知道可以使用*args
在函数中允许变量数量的多个参数。
此脚本在任意数量的字符串*sources
中查找一个word
:
def find(word, *sources):
for i in list(sources):
if word in i:
return True
source1 = "This is a string"
source2 = "This is Wow!"
if find("string", source1, source2) is True:
print "Succeed"
然而,有没有可能在一个函数中指定多个参数(*args)?在这种情况下,需要在多个*源中查找多个*单词。
比喻地说:
if find("string", "Wow!", source1, source2) is True:
print "Succeed"
else:
print "Fail"
我该如何让脚本区分哪些是单词
,哪些是源代码
?