python - 使用函数 1 的输出作为函数 2 的输入

标签 python function user-defined-functions

所以我有一些类似下面的代码:

def _step_1(a, b, c):
    some codes
    return d, e, f

def _step_2(d, e, f, a, b):
    some codes
    return g

def _run_all(a, b, c):
    g = _step_2(_step_1(a, b, c), a, b)
    return g

它告诉我缺少两个参数“a”和“b”。有人可以通过尝试节省一些步骤来告诉我我是否做错了什么吗?或者没有办法节省步骤?我知道我绝对可以这样写:

def _run_all(a, b, c):
    d, e, f = _step_1(a, b, c)
    g = _step_2(d, e, f, a, b)
    return g

最佳答案

如果你的版本是python 3,使用解包(*):

def _run_all(a, b, c):
  g = _step_2(*_step_1(a, b, c), a, b)
  return g

关于python - 使用函数 1 的输出作为函数 2 的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54938195/

相关文章:

jquery - colorSelect 函数将 alt 标签传递到输入字段

sql-server - SQL Server 2008 r2 - T-SQL LIKE 或 PATINDEX 匹配 A-Z、0-9、连字符、句点、下划线和波形符以外的字符

python - 如何递归调用python中的函数将列表中的每个元素拖到底部?

function - Scheme中函数的机制

c++ - 如何从整个代码的函数中打开文件?

php - 如何从 PHP 代码中调用 MySQL 存储过程?

c# - 使用 Entity Framework 4.0/.edmx 从 c# 调用标量函数

python - 为什么 post_save 在 Django 模型保存期间被提升两次?

python - python 细化、平均、舍入数据

Python对低值整数在内存中的布局