简体   繁体   English

我想在另一个 function 中使用 function 的结果

[英]I want to use the result of a function in another function

some_list = [ [ ], [ ], [ ] ]

def my_func(sum):
     ...
     a = 0
     b = 1
     return a, b

I'm trying to append to the given index in some_list by getting the index from a and b .我正在尝试通过从ab获取索引来将some_list到 some_list 中的给定索引。

What do I need to write so that this code below would work?我需要写什么才能使下面的代码起作用?

some_list[a].append(win)
some_list[b].append(loss)

Assign two variables at once to the call of your function, like this:一次将两个变量分配给 function 的调用,如下所示:

some_list = [ [ ], [ ], [ ] ]

def my_func(sum):
     ...
     a = 0
     b = 1
     return a, b

a, b = my_func(sum) # this here

some_list[a].append(win)
some_list[b].append(loss)

Assuming by 'work' you mean that you want to use the return value of the function as the index of an array.假设“工作”意味着您想使用 function 的返回值作为数组的索引。

a, b = my_func(whatever)
some_list[a].append(win)
some_list[b].append(loss)
some_list = [ [ ], [ ], [ ] ]

def my_func(sum):
     a = 0
     b = 1
     return a, b



sum = 5
a,b = my_func(sum)

win = 'aaa'
loss = 'bbb'
some_list[a].append(win)
some_list[b].append(loss)

print(some_list)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在另一个函数中使用函数的结果? - How can I use the result from a function in another function? 在 python 的另一个上使用 function 的结果 - Use the result of a function in another on in python 将函数与Python(sympy,quad)集成,结果是我要绘制的另一个函数 - Integrating a function with Python (sympy, quad) where the result is another function I want to plot 使用 spark 函数结果作为另一个函数的输入 - Use spark function result as input of another function 在另一个函数中使用一个函数的返回结果 - Use the result of the return of one function in another function 如何在 python 中将 function 的结果用于另一个 function? - How to use the result of a function to another function in python? 如何使用其他函数的结果? - How can I use the result from another function? 如果我想按一个标准升序排序并按另一个标准降序排序,我该如何使用 sort 函数? - How can i use the sort function if i want to sort ascending by a criterion and descending by another criterion? 在 class 中调用 function 并将结果用于另一个 function - call function inside class and use the result in another function python,我想在 for 循环中使用 function - python, I want to use function in for loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM