Dynamical output in Python Functions -
when use def, can use **kwargs , *args define dynamic inputs function
is there similar return tuples, i've been looking behaves this:
def foo(data): return 2,1 a,b=foo(5) a=2 b=1 a=foo(5) a=2
however if declare 1 value unpack, sends whole tuple on there:
a=foo(5) a=(2,1)
i use 'if' statements, wondering if there less cumbersome. use hold variable store value, return value might kind of large have place holder that.
thanks
if need generalize return value, this:
def function_that_could_return_anything(data): # stuff return_args = ['list', 'of', 'return', 'values'] return_kwargs = {'dict': 0, 'of': 1, 'return': 2, 'values': 3} return return_args, return_kwargs a, b = function_that_could_return_anything(...) thing in a: # stuff item in b.items(): # stuff
in opinion simpler return dictionary, access parameters get()
:
dict_return_value = foo() = dict_return_value.get('key containing a', none) if a: # stuff
Comments
Post a Comment