python - 我想在另一个函数中使用一个函数的结果

标签 python python-3.x

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

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

我试图通过从 ab 获取索引来附加到 some_list 中的给定索引。

我需要写什么才能让下面的代码起作用?

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

最佳答案

一次将两个变量分配给函数的调用,如下所示:

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)

关于python - 我想在另一个函数中使用一个函数的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58915554/

相关文章:

python - 为 cffi (setup.py) 构建轮子……从 django 中的 requirements.txt 安装包时出错

python - 变量初始化时收到 "UnboundLocalError: local variable ' e'赋值前引用"

python - 尝试使用 pandas 进行 pytest 测试时出现 Keyerror

python - 是否可以通过Python3中的属性来确定方法是否被调用?

python - 为什么织物使用/bin/sh

python 在for循环中删除一个元素

Python - 检查正在使用哪个子类

python - 为什么我的正向先行断言会消耗字符串并且无法正确匹配?

python - 寻找最大的质因数(最快的程序)

python - 将字节字符串转换为 base64 编码的字符串(输出不是字节字符串)