list Integer indexing dies??
ishwor.gurung at gmail.com
Thu Dec 23 15:47:05 CET 2004
On 23 Dec 2004 14:28:37 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:
> Op 2004-12-23, Ishwor schreef <ishwor.gurung at gmail.com>:
> > Hi all. Look at this snippet of code.
> >>>> l = ['a','b','c','d']
> >>>> l
> > ['a', 'b', 'c', 'd']
> >>>> l
> > 'a'
> > 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
> of characters.
> So 'a' is again 'a' which can again be indexed by
> 0 as many times as you want.
;-) gotcha. But shouldn't this be valid too??
in which basically python can infer from the object type and print out
1 instead of coughing up those errors? My experience as a learner here
is that there should be some automagics & say like "okay you want to
do indexing on integers ( context dependent); i'll give you the index
of 0th position in that integer" ???
More information about the Python-list