Python Forum

Full Version: How to call multiple functions sequentially
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys, I am trying to learn Python and I wonder if there is a better, more efficient solution to this.
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)
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
In my opinion the Option#2 is better and should be preferred over Option#1 - more clean, readable and easy to follow the flow of execution
Ok thank you