函数可以通过关键字参数的形式来调用
以下为一个示例
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’) 不知道的参数