我是一個Python新手,但我知道我可以允許在函數中使用*args
可變數目的多個參數。Python:「多個」函數中的多個參數
這個腳本會查找word
在任何數量的字符串*sources
的:
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
)在一個功能?在這種情況下,這將在多個*sources
中尋找多個*words
。
如,比喻:
if find("string", "Wow!", source1, source2) is True:
print "Succeed"
else:
print "Fail"
我怎樣才能使腳本辨別什麼是打算成爲一個word
,什麼是應該是一個source
?
如果你有多個多個參數你會怎樣調用這個函數? python如何知道哪個值放入哪個值? –