我已经阅读了用户定义python函数的this教程。你知道吗
本教程说:
def sum( arg1, arg2 ):
total = arg1 + arg2
return total;
# Now you can call sum Function
total = sum( 10, 20 );
print "Outside the function : ", total
在我的例子中,我有一个python函数:
def myf(arg1):
.................
some python progress
...................
return out1,out2,out3,out4,out5,out6
最后,我的主函数有6个输出
但是如果我试着像本教程那样调用函数:
myf = out1(myvar)
然后显示来自out1,out2,out4=3,out4,out5,out6
的所有输出,而不是我想要的具体位置。你知道吗
例如,我的函数的正确输出是:
out1=10,out2=30,out3=300,out4=12,out5=47,out6=77
那myf = out1(myvar)
告诉我:
(10,30,300,12,47,77) and not `10` where i want...
你知道如何从输出中得到我所需要的吗?你知道吗
您的函数正在返回一个值元组,这个元组被分配给
myf
。你知道吗如果只需要元组中的第n个值,可以通过
myf[n]
引用它。你知道吗在您的例子中,您正在寻找
myf[0]
。你知道吗相关问题 更多 >
编程相关推荐