Re: list Integer indexing dies??

Discussion in 'Python' started by Ishwor, Dec 23, 2004.

  1. Ishwor

    Ishwor Guest

    On Thu, 23 Dec 2004 11:17:57 -0300, Batista, Facundo
    <> 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
     
    Ishwor, Dec 23, 2004
    #1
    1. Advertising

  2. Ishwor wrote:
    > On Thu, 23 Dec 2004 11:17:57 -0300, Batista, Facundo
    >>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.


    5.2/3 is supported by Python, but 'a'/'b' isn't.

    --
    Serhiy Storchaka
     
    Serhiy Storchaka1745620946, Dec 23, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C
    Replies:
    0
    Views:
    508
  2. Ishwor

    list Integer indexing dies??

    Ishwor, Dec 23, 2004, in forum: Python
    Replies:
    10
    Views:
    499
    Mike Meyer
    Dec 24, 2004
  3. Ishwor
    Replies:
    2
    Views:
    266
    Dan Bishop
    Dec 23, 2004
  4. Emin
    Replies:
    4
    Views:
    412
    Paul McGuire
    Jan 12, 2007
  5. Christopher M. Lusardi
    Replies:
    3
    Views:
    198
    Alan J. Flavell
    Oct 19, 2003
Loading...

Share This Page