如何用参数获取函数的返回值?(How to get the return values of function with arguments?)

我正在开发一个python练习,需要获取函数的字符串返回值。 以下是与我目前正在使用的示例代码相关的示例代码。

def main(): x = 'the quick' y = 'brown fox' return x, y def function1(x, y): if x == 'the quick' and y == 'brown fox': return 'jump' else: return 'lazy' def function2(): if a == 'jump': print('good boy') else: print('bad boy') function2(*function1(*main()))

我收到位置参数错误。 如何正确返回其他函数的字符串?

I'm working on a python exercise that requires getting the string return values of function. Here is the sample code that is related to the one I'm currently working on.

def main(): x = 'the quick' y = 'brown fox' return x, y def function1(x, y): if x == 'the quick' and y == 'brown fox': return 'jump' else: return 'lazy' def function2(): if a == 'jump': print('good boy') else: print('bad boy') function2(*function1(*main()))

I'm getting positional argument error. How to return the string properly for other function?

最满意答案

首先你必须为function2指定参数:我想你想用这种方式定义function2:

def function2(a): if a == 'jump': print('good boy') else: print('bad boy')

你可能想要funtion2输出'好孩子',这样,你可以尝试:

function2(function1(*main()))

这将给你想要的输出。

At first you have to specify parameters for function2: I guess you want to define function2 in this way:

def function2(a): if a == 'jump': print('good boy') else: print('bad boy')

And you may want funtion2 output 'good boy', In this way, you could try:

function2(function1(*main()))

Which will give the output as you want.

更多推荐