函數可以通過關鍵字參數的形式來調用
以下為一個示例
def parrot(voltage, state=’a stiff’, action=’voom’, type=’Norwegian Blue’):
print "-- This parrot wouldn’t", action,
print "if you put", voltage, "volts through it."
print "-- Lovely plumage, the", type
print "-- It’s", state, "!"
could be called in any of the following ways:
正確的調用
parrot(1000)
parrot(action = ’VOOOOOM’, voltage = 1000000)
parrot(’a thousand’, state = ’pushing up the daisies’)
parrot(’a million’, ’bereft of life’, ’jump’)
but the following calls would all be invalid:
以下調用是不正確的
parrot() # required argument missing
parrot(voltage=5.0, ’dead’) 沒有關鍵字參數
parrot(110, voltage=220) 定義了重復的值
parrot(actor=’John Cleese’) 不知道的參數