() vs []

Chris Rebert clp2 at rebertia.com
Thu Oct 15 04:39:07 EDT 2009


On Thu, Oct 15, 2009 at 1:27 AM, Xavier Ho <contact at xavierho.com> wrote:
> On Thu, Oct 15, 2009 at 3:21 AM, Nanjundi <nanjundi at gmail.com> wrote:
>> 3       You can’t find elements in a tuple. Tuples have no index method.
>
> I don't know what language you're using there, but my Python tuples have
> indexes.
>
>>>> a = (1, 2, 3)
>>>> a
> (1, 2, 3)
>>>> a[1]
> 2

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.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list