On 23 Dec 2004 15:05:20 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: > Op 2004-12-23, Ishwor schreef <[EMAIL PROTECTED]>: > > On 23 Dec 2004 14:28:37 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: > >> Op 2004-12-23, Ishwor schreef <[EMAIL PROTECTED]>: > >> > Hi all. Look at this snippet of code. > >> > > >> >>>> l = ['a','b','c','d'] > >> >>>> l > >> > ['a', 'b', 'c', 'd'] > >> >>>> l[0][0][0] > >> > 'a' > >> > It prints the value 'a'. Fine so far :-) > >> > l[0] ---> 'a' . > >> > l[0][0]---> 'a'[0] --> 'a'. > >> > l[0][0][0] ---> 'a'[0][0] --> 'a'[0] --> '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'[0] is again 'a' which can again be indexed by > >> 0 as many times as you want. > > > > ;-) gotcha. But shouldn't this be valid too?? > >>>> 123232[0] > > Well if it should become valid, it should just return 123232 IMO. > Im not sure i understand u but what i meant was that >>> 123 + 2 125 # nice n good
now it would be nice if integer could also be *subscripted* too >>> 123[0] + 2 3 ;-) But as i said in earlier post said, i'll stick with import this's #2 by Tim Peters. Its better to leave these design issues with other **senior pythoneers**. > > in which basically python can infer from the object type and print out > > 1 instead of coughing up those errors? > > Why do you feel it should cough up 1? > >>>123232[0] #hypothetical 0th position in the integer. 1 > Suppose I write a number in octal notation. > > What should 035[0] cough up? Be carefull it should >>>035[0] 3 # my own opinion. > cough up the same as 29[0]. >>>29[0] 2 #again my own opinion [snip] > by starting indexing from the back we get a nice correspondence between > the index of the number and the power of 10 it represents. > > -- > Antoon Pardon > -- > http://mail.python.org/mailman/listinfo/python-list > As in my view if python could treat object in context sensitive manner, it would be better world but its just my own beginners opinion. Happy hunting with Python. ;-) -- cheers, Ishwor Gurung -- http://mail.python.org/mailman/listinfo/python-list