Tuple question

Will McGugan news at NOwillmcguganSPAM.com
Thu Sep 2 12:40:27 EDT 2004


Wai Yip Tung wrote:

> I'm not sure what do you mean by index. But you can use len() to get 
> the  number of objects in a tuple. e.g.
> 
>>>> t=(1,2,3)
>>>> len(t)
> 
> 3
> 
>>>> t[2]
> 
> 3
> 

Lista have an index method that returns the index of the first occurance 
of an element, but tuple doesnt (nor count). Just wondering why.

 >>> l= [ 1, 2, 3 ]
 >>> t= ( 1, 2, 3 )
 >>> l.index(2)
1
 >>> t.index(2)
Traceback (most recent call last):
   File "<pyshell#8>", line 1, in ?
     t.index(2)
AttributeError: 'tuple' object has no attribute 'index'



More information about the Python-list mailing list