First page Back Continue Last page Overview Graphics

Variable Length Argument List

Functions can use special arguments preceded with * characters

to collect arbitrarily extra arguments (similar to the varargs feature

in C).

def varlength(x, y, *more):

print("x=", x, ", y=", y)

print("more: ", more)

x and y are regular (positional) parameter, while *more references a tuple.

>>> varlength(3,4)

x= 3 , y= 4

more: ()

>>> varlength(3,4,"Hello World", 42)

x= 3 , y= 4

more: ('Hello World', 42)