What is pythonic best practice for allowing one function to use another function’s returned values? e.g. Is it better to call one function within another, or better that function1 returns to the class, and class variables are assigned that are then used by function2? Secondly, how many different ways could you pass values between functions?
class adding:
def get_values(self):
x = input("input x")
y = input("input y")
z = input("input z")
return x, y, z
def use_values(self, x, y, z):
print x+y+z
if name == 'main':
dave = adding()
x, y, z = dave.get_values()
dave.use_values(x, y, z)
Or
dave = adding()
dave.use_values(*dave.get_values())
As
import thiswould say, “explicit is better than implicit”; so go with the first form.If the number of return values becomes large, let
use_valuetake a sequence argument instead.