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
How about:
def myfunc(a, bret=False, cret=False):
...
return (a,) + ((b,) if bret else ()) + ((c,) if cret else ())
def myfunc (a, bret=False, cret=False):
b, c, ret = 0, 0, [a]
if bret: ret.append(b)
if cret: ret.append(c)
return ret
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With