Is it possible to return two lists from a function in python

后端 未结 2 948
借酒劲吻你
借酒劲吻你 2020-12-24 13:25

I am new to python programming and need your help for the following:

I want to return two lists from a function in python. How can i do that. And how to read them in

2条回答
  •  我在风中等你
    2020-12-24 14:09

    You can return as many value as you want by separating the values by commas:

    def return_values():
        # your code
        return value1, value2
    

    You can even wrap them in parenthesis as follows:

    return (value1, value2)
    

    In order to call the function you can use one of the following alternatives:

    value1, value2 = return_values() #in the case where you return 2 values
    
    values= return_values() # in the case values will contain a tuple
    

提交回复
热议问题