[Tutor] (no subject)
Kent Johnson
kent37 at tds.net
Fri Jan 19 19:42:41 CET 2007
Max Jameson wrote:
> I know this is totally off-the-wall, but what am I doing wrong here? I
> am using Python 2.5, and I am just learning...please be kind!
>
>
>
>
> >>> aList = [2,3]
> >>> bList = [5,7,9]
> >>> aList.append(bList)
> >>> print aList
> [2, 3, [5, 7, 9]]
> >>> print aList [1] [2]
What did you expect to happen here?
alist[1][2] is the same as (alist[1])[2]; in other words, it is the
third item in the second item in alist. The second item (alist[1]) is
the integer 3 which is not subscriptable; if you try 3[2] at the
interactive prompt you will get the same error.
If you are trying to get the elements of bList out of aList you should
try alist[2][0], alist[2][1] etc.
Kent
>
> Traceback (most recent call last):
> File "<pyshell#40>", line 1, in <module>
> print aList [1] [2]
> TypeError: 'int' object is unsubscriptable
> >>> print aList [0] [1]
>
> Traceback (most recent call last):
> File "<pyshell#41>", line 1, in <module>
> print aList [0] [1]
> TypeError: 'int' object is unsubscriptable
> >>>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list