Jan-06-2021, 07:04 PM
Hello guys, I am trying to learn Python and I wonder if there is a better, more efficient solution to this.
I have a code which i seperated in 3 functions to have an easier overview of the code. I use the value I retrieve from the first function in the second function, and the second value in the third function.
Can you tell me if Option 1 or 2 is more efficient? Or maybe if there is a cleaner way to use multiple functions.
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
def firstCalc(): a = 2 + 2 return a def secondCalc(a): b = 3 + a return b def thirdCalc(b): c = b + 7 return c # Option 1 x = thirdCalc(secondCalc(firstCalc())) print (x) # Option 2 a = firstCalc() b = secondCalc(a) c = thirdCalc(b) print (c) |
Can you tell me if Option 1 or 2 is more efficient? Or maybe if there is a cleaner way to use multiple functions.
Thanks