[Tutor] variable number of inputs
bgailer at gmail.com
Thu Jan 8 04:01:42 CET 2009
Mr Gerard Kelly wrote:
> How can you make a function accept a variable number of inputs without
> any particular limit?
> Like when you define a function you usually go:
> def func(a,b,c,d,e)
> and if you want to give a default value for e you can use e=0 for example.
> But what if you want to be able to call the function and put in as many
> arguments as you want. Say it's a really simple function just adding
> them all together or something (I know sum does that, but I'm just
> thinking of a simple example).
def func(*a) # a will be a tuple of whatever arguments are passed in the call.
Chapel Hill NC
More information about the Tutor