Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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 - Fatal编程技术网

在python中将循环数据存储在单独的变量中?

在python中将循环数据存储在单独的变量中?,python,Python,我想将返回函数中的循环数据存储到单独的变量中。这是我的密码 如果有错,请纠正我 功能: def rawi(): a = raw_input("enter value of a") b = raw_input("enter value of b") return a, b #calling the above function: c = rawi() for i in c: print i 我想要的输出应该是: varia

我想将返回函数中的循环数据存储到单独的变量中。这是我的密码 如果有错,请纠正我

功能:

 def rawi():
        a = raw_input("enter value of a")
        b = raw_input("enter value of b")
        return a, b

 #calling the above function:

 c = rawi()


 for i in c:
     print i
我想要的输出应该是: variable1应具有从 variable2应该具有从b返回的值


谢谢

你是说像下面这样的话吗

variable1, variable2 = rawi()

你是说像下面这样的事情吗

variable1, variable2 = rawi()

如果在c中循环,则函数应如下所示:

def rawi():
    a = raw_input("enter value of a")
    b = raw_input("enter value of b")
    return (a, b) #you can return tuple/list/whatever that stores multiple variables

如果在c中循环,则函数应如下所示:

def rawi():
    a = raw_input("enter value of a")
    b = raw_input("enter value of b")
    return (a, b) #you can return tuple/list/whatever that stores multiple variables

我喜欢括号,但它们不是严格必需的,因为
运算符创建元组。我喜欢括号,但它们不是严格必需的,因为
运算符创建元组。