什么时候是不可变的元组*必不可少*?为什么你不能只使用列表*到处*? [英] When are immutable tuples *essential*? Why can't you just use lists *everywhere* instead?

查看:104
本文介绍了什么时候是不可变的元组*必不可少*?为什么你不能只使用列表*到处*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我想一个不可变元组是必不可少的例子。


似乎无论使用哪个元组都可以轻松使用

a list。


chris

解决方案

< a href =mailto:se ****** @ spawar.navy.mil> se ****** @ spawar.navy.mil 写道:


请帮助我想一个不可变元组是必不可少的例子。



当用作字典键时(在其他任何地方,他们必须按照常数顺序使用
)。

是的,* *在实践中使用。


问候,

Bj?


-

BOFH借口#14:


听起来像是Windows问题,请尝试致电Microsoft支持


4月20日下午2:06,seber ... @ spawar.navy.mil

< seber ... @ spawar.navy.milwrote :


请帮助我想一个不可变元组是必需元素的例子。


似乎无论使用哪个元组,都可以轻松使用

a列表。


chris



我不记得我读到的确切位置,但Guido曾经说过,因为历史原因,元组主要被保留了。

这就是Python在内部使用开始,它只是

一个在某些情况下有意义的实现细节。

虽然我猜你可以忽略它们而只使用列表代替你/ br / >
想要..


luis


LuisM.González写道:


我不记得我读到的确切内容,但是Guido说,一旦这些元组主要是出于历史原因而保留了



当列表已经存在时,我们不会添加元组吗?


问候,

Bj ?$

-

BOFH借口#101:


倒塌的骨干


Please help me think of an example where immutable tuples are
essential.

It seems that everywhere a tuple is used one could just as easily use
a list instead.

chris

解决方案

se******@spawar.navy.mil wrote:

Please help me think of an example where immutable tuples are
essential.

When used as dictionary keys (also everywhere else where they must
be in a constant order).

Yes, this *is* used in practice.

Regards,
Bj?rn

--
BOFH excuse #14:

sounds like a Windows problem, try calling Microsoft support


On Apr 20, 2:06 pm, "seber...@spawar.navy.mil"
<seber...@spawar.navy.milwrote:

Please help me think of an example where immutable tuples are
essential.

It seems that everywhere a tuple is used one could just as easily use
a list instead.

chris


I don''t remember exactly where I read about it, but Guido said once
that tuples are being kept mainly for historical reasons.
This is what Python uses internally from the beginning and it''s just
an implementation detail that makes sense in some contexts.
Although I guess you can ignore them and use only lists instead if you
want..

luis


Luis M. González wrote:

I don''t remember exactly where I read about it, but Guido said
once that tuples are being kept mainly for historical reasons.

Weren''t tuples added when lists already existed?

Regards,
Bj?rn

--
BOFH excuse #101:

Collapsed Backbone


这篇关于什么时候是不可变的元组*必不可少*?为什么你不能只使用列表*到处*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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