tuple.index() [英] tuple.index()

查看:104
本文介绍了tuple.index()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为什么元组类型没有索引方法?这似乎是一个奇怪的限制,必须有一些原因。是的,

我知道这是一个相当罕见的要求。

问候,

Nick Maclaren。


Why doesn''t the tuple type have an index method? It seems such a
bizarre restriction that there must be some reason for it. Yes,
I know it''s a fairly rare requirement.
Regards,
Nick Maclaren.

推荐答案

Nick Maclaren写道:
Nick Maclaren wrote:

为什么元组类型没有索引方法?这似乎是一个奇怪的限制,必须有一些原因。
Why doesn''t the tuple type have an index method? It seems such a
bizarre restriction that there must be some reason for it.



哈!无法删除或添加到元组的东西是一个偶然的限制!


< / F>

hah! not being able to remove or add things to tuples is an even
bizarrer restriction!

</F>




文章< ma *************************** ************@蟒蛇。 org>,

Fredrik Lundh< fr ***** @ pythonware.comwrites:

|>

|为什么元组类型没有索引方法?好像是这样的
|奇怪的限制,必须有一些理由。

|>

|哈!无法删除或添加元组的东西是一个偶然的

|奇怪的限制!


Eh?为什么?


我对元组和列表之间差异的理解是

实际上前者是不可变的而后者是可变的。

但是一个索引方法在一个不可变的

序列中就像在一个可变的序列上一样有意义。

问候,

Nick Maclaren。

In article <ma***************************************@python. org>,
Fredrik Lundh <fr*****@pythonware.comwrites:
|>
| Why doesn''t the tuple type have an index method? It seems such a
| bizarre restriction that there must be some reason for it.
|>
|hah! not being able to remove or add things to tuples is an even
|bizarrer restriction!

Eh? Why?

My understanding of the difference between a tuple and a list is
PRECISELY that the former is immutable and the latter mutable.
But an index method makes precisely as much sense on an immutable
sequence as it does on a mutable one.
Regards,
Nick Maclaren.


Nick Maclaren写道:
Nick Maclaren wrote:

为什么元组类型没有索引方法?这似乎是一个奇怪的限制,必须有一些原因。
Why doesn''t the tuple type have an index method? It seems such a
bizarre restriction that there must be some reason for it.



实际上,元组根本没有非-__ underscored__方法。列表

count()方法对于元组也很有用,因为它没有修改

任何东西。我不知道为什么他们也没有实施。


格伦

In fact, tuples have no non-__underscored__ methods at all. The list
count() method would also be useful for tuples, since it doesn''t modify
anything. I have no idea why they aren''t implemented either.

Glenn


这篇关于tuple.index()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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