Skip to main content
 首页 » 编程设计

python之如何不将函数用作其他函数的参数

2025年01月19日18artech

我正在尝试编写一些函数来确定实根数和二次方程的根数,我必须使用 main() 函数来完成。我试图避免的是将最终函数与所有其他函数一起用作其参数,例如

def main(): 
    function4(function3(function2(function1())), function2(function1())) 

相反,我怎样才能让它看起来像:

def main(): 
    function1() 
    function2() 
    function3() 
    function4() 

请您参考如下方法:

这应该是等价的。

def main(): 
    result1 = function1() 
    result2 = function2(result1) 
    result3 = function3(result2) 
    final_result = function4(result3, result2)