[Tutor] variable number of inputs

bob gailer 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.


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239



More information about the Tutor mailing list