1

I was trying to pass two variables returned from one function to the next function but but I'm not really understanding what am I missing, i always get the error -

TypeError: Function2() takes exactly 2 arguments (0 given)

My Code:

Function1(arg1, arg2):
# This two args to this function are taken from the user and some work is done here and this function will return two things as output (my_list1 is a list) - 
return my_list1, count

Function2 (argg1, argg2):
# This function will get the first and second argument from the previous function (Function1)

def main():
                Function1(list1, count1)
                myfinal_list, final_count = Function1()
                Function2(myfinal_list, final_count)

if __name__== "__main__":
        main()

How can I achieve this? What would I have to do to make sure data from the first function will be sent to the second function? Thank you!

2
  • 3
    Why are you calling again Function1() without any arguments? Do myfinal_list, final_count = Function1(list1, count1) Commented Jan 8, 2019 at 11:55
  • Understood the logic behind it. thanks! Commented Jan 8, 2019 at 12:08

2 Answers 2

2

Try this:

def main():        
    myfinal_list, final_count = Function1(list1, count1)
    Function2(myfinal_list, final_count)

Since this sentence myfinal_list, final_count = Function1() will give you an error because you are calling a Funcion1 with no arguments (while 2 are expected).

Sign up to request clarification or add additional context in comments.

2 Comments

so that means, Function1(list1, count1) will have values that were returned and get's assigned to myfinal_list, final_count ?
Thank you Pablo. Working as expected. Understood the logic behind it.
2

You're very close, but just missing one part:

In short, you have to include the arguments when calling the function. For instance, in the line: myfinal_list, final_count = Function1() you don't call either argument.

Accordingly, main() should be rewritten as follows:

def main():
    myfinal_list, final_count = Function1(list1, count1)
    Function2(myfinal_list, final_count)

1 Comment

Thanks Darcy, got it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.