best practice for passing values between functions in Python

后端 未结 3 579
猫巷女王i
猫巷女王i 2021-02-05 22:08

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 functi

3条回答
  •  不知归路
    2021-02-05 22:34

    I would argue that get_values is not a vital part of adding and should thus be a separate function. If it should be I would say:

    class adding:
    
    def get_values(self):
        self.x = input("input x")
        self.y = input("input y")
        self.z = input("input z")
    
    def use_values(self):
        print self.x+self.y+self.z
    
    if name == 'main':
        dave = adding()
        dave.get_values()
        dave.use_values()
    

    is a more sound solution.

提交回复
热议问题