元组有什么用? [英] What is a tuple useful for?

查看:42
本文介绍了元组有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在为一个班级学习 Python,我们刚刚介绍了元组作为数据类型之一.我在上面阅读了维基百科页面,但是,我无法弄清楚这种数据类型在实践中的用处.我可以举一些例子,也许在 Python 中,需要一组不可变的数字吗?这与列表有何不同?

I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in practice. Can I have some examples, perhaps in Python, where an immutable set of numbers would be needed? How is this different from a list?

推荐答案

  • 只要您想从函数中返回多个结果,就会使用元组.
  • 因为它们是不可变的,所以它们可以用作字典的键(列表不能).
  • 这篇关于元组有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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