如何在Python中为return语句的输出分配变量

如何在Python中为return语句的输出分配变量,python,Python,我有一个带有返回语句的函数,返回一个列表。我想将此列表存储在一个变量中,以便在下面的另一个函数中使用它。我该怎么做 def myFunction(): myList = [1 , 2 , 4 , 5] return myList z = myFunction() # z has value of myList 您还可以返回列表并为其分配变量,如: def myFunction(): return [1 , 2 , 4 , 5] z = myFunction() #

我有一个带有返回语句的函数,返回一个列表。我想将此列表存储在一个变量中,以便在下面的另一个函数中使用它。我该怎么做

def myFunction():
    myList = [1 , 2 , 4 , 5]
    return myList

z = myFunction() # z has value of myList
您还可以返回列表并为其分配变量,如:

def myFunction():
    return [1 , 2 , 4 , 5]

z = myFunction() # z has value of myList
要在其他功能中使用它,请执行以下操作:

def anotherFunction(z):
    # do something with the list
    return # whatever you need to return

def myFunction():
    myList = [1 , 2 , 4 , 5]
    return myList

z = myFunction() # z has value of myList
anotherFunction(z)

欢迎来到StackOverflow!请查看中定义的询问指南。