回复: () vs []

SmokingDog smokingdog.net at qq.com
Thu Oct 15 10:59:12 CEST 2009


the value 5 not in tuple 
reference help
 
list.index(x) 
Return the index in the list of the first item whose value is x. It is an error if there is no such item.
 
------------------
Eric Lee



 
 
 
------------------ 原始邮件 ------------------
发件人: "Chris Rebert"<clp2 at rebertia.com>;
发送时间: 2009年10月15日(星期四) 下午4:48
收件人: "Xavier Ho"<contact at xavierho.com>;
主题: Re: () vs []

 
On Thu, Oct 15, 2009 at 1:46 AM, Xavier Ho <contact at xavierho.com> wrote:
>
> On Thu, Oct 15, 2009 at 6:39 PM, Chris Rebert <clp2 at rebertia.com> wrote:
>>
>> Nanjundi meant "index method" as in "a method .index()" (i.e. a method
>> named "index") which searches through the container for the given item
>> and returns the index of the first instance of said item, like
>> list.index() does.
>>
> Interesting interpretation.. but I just gave it a try.
>
>>>> a = (1,2,3,4)
>>>> a
> (1, 2, 3, 4)
>>>> a.index(3)
> 2
>>>> a.index(5)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> ValueError: tuple.index(x): x not in tuple
>
> So my Python is saying that tuples do implement .index() method. What gives?
>
> Or maybe the diveintopython version he's quoting is out of date?

Apparently...or something stranger.

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091015/e80724f7/attachment.html>


More information about the Python-list mailing list