[Tutor] Why cant I return more than once here?

Kent Johnson kent37 at tds.net
Sun Mar 27 03:09:32 CEST 2005


gerardo arnaez wrote:
> Hi all, I am working a simple function 
> and want it return a
> a float
> a list
> and a dictionary
> 
> But it seems that I can only use
> return once in the function
> cant see to figure out why I can return more than once?
> Thanks for the help!

'return' does two things - it specifies what values to return, and it exits the function. You can 
return as many values as you want but it has to be all from one return statement.

>     return InitalCoumadinWeekRegimen
>     return reduce ((lambda x,y: x+y), CoumadinValuesList), CoumadinValuesList

Just put all the values in one return:
return InitalCoumadinWeekRegimen, reduce ((lambda x,y: x+y), CoumadinValuesList), CoumadinValuesList

BTW reduce ((lambda x,y: x+y), CoumadinValuesList) is the same as sum(CoumadinValuesList)

Kent



More information about the Tutor mailing list