函数可以通过使用kwarg = value的形式被调用,例如如下函数。翻译(Functions can also be called using keyword arguments of
the form kwarg= value.For instance,the following function:)
def Fun(nameID = 'xiaoliang', state = 'work hard', action = 'strong', type = 'Norwegih Blue'):
print("--This student doesn't to be", action, end=' ')
print("if you put", nameID, "a high position")
print("--Lovely plumage, the", type)
print("--It doesn't", state, "!")
if __name__ == "__main__":
Fun('xiaofei', 'Persistence', action='work hard')
Fun('zhuxiaoliang')
输出结果如下。在函数调用中,关键字参数必须遵循位置参数。所有传递的关键字参数必须匹配函数所接受的参数之一,它们的顺序并不重要。