[Tutor] Tuple indexing

Ian D duxbuz at hotmail.com
Wed Mar 11 15:08:18 CET 2015


Hi



I have seen some examples that seem to use a tuple with a method called index()


The original code I was looking at had this sort of thing:



SENSORS =  ('sensor1', 'sensor2')



                pin_index = SENSORS.index("sensor1")


so the result is that pin_index the is equal to 0


I then read that a Tuple has no attribute index on this site http://www.diveintopython.net/native_data_types/tuples.html


>>> t.index("example") 
Traceback (innermost last): File "<interactive input>", line 1, in ? AttributeError: 'tuple' object has no attribute 'index'



The example seems to work with 2.7 and 3.3 for me.





But I don't find much documentation on indexing Tuples using this method.



I am just wondering if there is more specific documentation on using Tuples this way



Thanks.



I am using Python 2.7 at moment.



   

  		 	   		  


More information about the Tutor mailing list