我试图将从一个函数返回的两个变量传递给下一个函数,但是我并没有真正理解我缺少什么,我总是会收到错误-
TypeError: Function2() takes exactly 2 arguments (0 given)
我的代码:
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()
我该如何实现?我该怎么做才能确保将第一个功能中的数据发送到第二个功能中? 谢谢!
答案 0 :(得分:2)
尝试一下:
def main():
myfinal_list, final_count = Function1(list1, count1)
Function2(myfinal_list, final_count)
由于这句话myfinal_list, final_count = Function1()
会给您一个错误,因为您正在调用不带参数的Funcion1
(预期为2)。
答案 1 :(得分:2)
您非常亲密,但是缺少一部分:
简而言之,在调用函数时必须包含参数。例如,在行<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<button class="btn-toggle-1"><span>boton</span></button>
<p class="cprice">demo</p>
<div id="section-contact">element at scroller</div>
中,您不会调用任何一个参数。
因此,myfinal_list, final_count = Function1()
应该被重写如下:
main()