是否可以从python中的函数返回两个列表 [英] Is it possible to return two lists from a function in python

查看:68
本文介绍了是否可以从python中的函数返回两个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 编程的新手,在以下方面需要您的帮助:

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

我想从 python 中的函数返回两个列表.我怎样才能做到这一点.以及如何在主程序中读取它们.示例和插图会很有帮助.

I want to return two lists from a function in python. How can i do that. And how to read them in the main program. Examples and illustrations would be very helpful.

提前致谢.

推荐答案

可以返回一个列表元组,调用函数时使用序列解包将它们分配给两个不同的名称:

You can return a tuple of lists, an use sequence unpacking to assign them to two different names when calling the function:

def f():
    return [1, 2, 3], ["a", "b", "c"]

list1, list2 = f()

这篇关于是否可以从python中的函数返回两个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆