list Integer indexing dies??
apardon at forel.vub.ac.be
Thu Dec 23 15:28:37 CET 2004
Op 2004-12-23, Ishwor schreef <ishwor.gurung at gmail.com>:
> Hi all. Look at this snippet of code.
>>>> l = ['a','b','c','d']
> ['a', 'b', 'c', 'd']
> It prints the value 'a'. Fine so far :-)
> l ---> 'a' .
> l---> 'a' --> 'a'.
> l ---> 'a' --> 'a' --> 'a'
> Now why doesnt this list which holds integer seem to work??
Because this only works with strings.
String is the only object in python which has an implied
equivallence between an element and a squence of one.
So one character is a string and a string is a sequence
So 'a' is again 'a' which can again be indexed by
0 as many times as you want.
I think python would have been more consistent if
strings would have been tuples of chars and maybe
implied an equivalence between whatever object and
a singleton of that object.
More information about the Python-list