Python Forum
How to call multiple functions sequentially - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to call multiple functions sequentially (/thread-31855.html)



How to call multiple functions sequentially - Mayo - Jan-06-2021

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


RE: How to call multiple functions sequentially - buran - Jan-06-2021

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


RE: How to call multiple functions sequentially - Mayo - Jan-06-2021

Ok thank you