Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:函数参数和返回值_Python_Function - Fatal编程技术网

Python:函数参数和返回值

Python:函数参数和返回值,python,function,Python,Function,假设我有一个函数 def equals_to(x,y): a + b = c def some_function(something): for i in something: ... 有没有一种方法可以使用由equals_to计算的c作为某个函数的参数 equals_to(1,2) some_function(c) 您需要从函数中返回c的值 def equals_to(x,y): c = x + y # c = x + y not a + b = c

假设我有一个函数

def equals_to(x,y):
 a + b = c
def some_function(something):
 for i in something:
 ...
有没有一种方法可以使用由
equals_to
计算的
c
作为
某个函数的参数

equals_to(1,2)
some_function(c)

您需要从函数中返回
c
的值

def equals_to(x,y):
    c = x + y           # c = x + y not a + b = c
    return c            # return the value of c 

def some_function(something):
    for i in something:
    ... 
    return 

sum = equals_to(1,2)     # set sum to the return value from the function 
some_function(sum)       # pass sum to some_function
另外,
equals__to
的函数签名采用参数
x,y
,但在您使用的函数
a,b
中,赋值方式错误,
c
采用
x+y
的值,而不是
a+b
equals
c


强烈建议:

您需要
从函数返回
c
的值

def equals_to(x,y):
    c = x + y           # c = x + y not a + b = c
    return c            # return the value of c 

def some_function(something):
    for i in something:
    ... 
    return 

sum = equals_to(1,2)     # set sum to the return value from the function 
some_function(sum)       # pass sum to some_function
另外,
equals__to
的函数签名采用参数
x,y
,但在您使用的函数
a,b
中,赋值方式错误,
c
采用
x+y
的值,而不是
a+b
equals
c


强烈推荐:

什么是
c
a
b
?他们是从哪里来的?我对你想要实现的目标感到非常困惑
equals_to
不编译,它看起来是要返回一个整数,这在blah
语句中对x不起作用。`def equals_to(x,y)`应该说
def equals_to(a,b)
我在键入示例时犯了一个错误。而且
a+b=c
应该是
c=a+b
什么是
c
a
b
?他们是从哪里来的?我对你想要实现的目标感到非常困惑
equals_to
不编译,它看起来是要返回一个整数,这在blah
语句中对x不起作用。`def equals_to(x,y)`应该说
def equals_to(a,b)
我在键入示例时犯了一个错误。而且
a+b=c
应该是
c=a+b