读书人

python中急需留心的3

发布时间: 2012-09-14 23:00:49 作者: rapoo

python中需要留心的3
Arbitrary Argument Lists

Finally, the least frequently used option is to specify that a function can be called with an arbitrary number of arguments. These arguments will be wrapped up in a tuple (see Tuples and Sequences). Before the variable number of arguments, zero or more normal arguments may occur.

>>> def parrot(voltage, state='a stiff', action='voom'):...     print "-- This parrot wouldn't", action,...     print "if you put", voltage, "volts through it.",...     print "E's", state, "!"...>>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}>>> parrot(**d)-- This parrot wouldn't VOOM if you put four million volts through it. E's bleedin' demised !

读书人网 >perl python

热点推荐