list Integer indexing dies??
Ishwor
ishwor.gurung at gmail.com
Thu Dec 23 09:35:26 EST 2004
On Thu, 23 Dec 2004 11:17:57 -0300, Batista, Facundo
<FBatista at unifon.com.ar> wrote:
>
[snip]
> #- >>> 1[0]
> #-
> #- Traceback (most recent call last):
> #- File "<pyshell#246>", line 1, in -toplevel-
> #- 1[0]
> #- TypeError: unsubscriptable object
> #- >>>
>
> Well, because the integer is not a subscriptable object....
>
If i see this code 'a'[0] then what does it really say about semantics
?? Really its hard for me to digest that 'a'[0] is supported by Python
where as 1[0] isn't.
look at this
>>> 'invalid'[0]
'i'
>>> 123232[-1]
# Python should automagically infer here that user
# means indexing and *not* the number per se.
# (i mean list in context of the line :-) )
Traceback (most recent call last):
File "<pyshell#284>", line 1, in -toplevel-
123232[-1]
TypeError: unsubscriptable object
> IOW, the string is a sequence of characters, and the integer is not sequence
> at all.
>
strings are immutable sequence of collections in Python. Integers are
numbers. ;-)
> >>> 'a'[0]
> 'a'
> >>> 'ab'[0]
> 'a'
> >>> 'ab'[1]
> 'b'
>
> What behaviour did you expect when subscripting an integer?
>
I got unscriptable object TypeError (extract below) which is *now*
with your enlightment clear to me ;-)
>>> 1[0]
Traceback (most recent call last):
File "<pyshell#246>", line 1, in -toplevel-
1[0]
TypeError: unsubscriptable object
>>>
> . Facundo
>
> Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
> PyAr - Python Argentina: http://pyar.decode.com.ar/
>
[snip]
Thanks Batista.
--
cheers,
Ishwor Gurung
More information about the Python-list
mailing list