return value in Python

python, return, return-value

Solution

How about:

def myfunc(a, bret=False, cret=False):
   ...
   return (a,) + ((b,) if bret else ()) + ((c,) if cret else ())

Problem

I would like my function to return 1, 2, or 3 values, in regard to the value of `bret` and `cret`. How to do something more clever than this ? : ``` def myfunc (a, bret=False, cret=False): b=0 c=0 if bret and cret: return a,b,c elif bret and not cret: return a,b elif not bret and cret: return a,c else: return a ```

Original source

Related problems