Python Forum
How to call multiple functions sequentially
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call multiple functions sequentially
#1
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
Reply
#2
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
Mayo likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Ok thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Are list/dict comprehensions interpreted really sequentially? anata2047 3 1,412 May-31-2022, 08:43 PM
Last Post: Gribouillis
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,265 Dec-04-2021, 08:33 PM
Last Post: Ascalon
  Defining multiple functions in the same def process sparkt 5 2,750 Aug-09-2020, 06:19 PM
Last Post: sparkt
  module to store functions/variables and how to call them? mstichler 3 2,338 Jun-03-2020, 06:49 PM
Last Post: mstichler
  Multiple lambda functions in zipped list not executing psolar 0 1,569 Feb-13-2020, 12:53 PM
Last Post: psolar
  naming images adding to number within multiple functions Bmart6969 0 1,892 Oct-09-2019, 10:11 PM
Last Post: Bmart6969
  Call functions recursively in tree structure using python dubru 1 2,250 Feb-15-2019, 06:43 PM
Last Post: nilamo
  Time multiple functions within functions Cortessizzz 4 3,076 Jan-09-2019, 04:15 PM
Last Post: Cortessizzz
  How can I link these 6 routines to run sequentially? Pedroski55 2 2,591 Sep-16-2018, 04:42 AM
Last Post: Pedroski55
  call a function from other functions ... evilcode1 2 2,692 Sep-05-2018, 09:07 AM
Last Post: evilcode1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020