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, "!"
我开始学习python。我可以使用parrot(5,'dead')和parrot(voltage=5)调用这个函数。但是为什么我不能用parrot的相同函数调用(voltage=5,'dead')?在
不能在关键字参数(
arg_name='arg_value'
)之后使用非关键字参数('arg_value'
)。这是因为Python是如何设计的。在请看这里:http://docs.python.org/tutorial/controlflow.html#keyword-arguments
因此,必须输入关键字参数后面的所有参数作为关键字参数。。。在
相关问题 更多 >
编程相关推荐