[Tutor] Arrays
Sean 'Shaleh' Perry
shaleh@valinux.com
Sun, 3 Sep 2000 00:42:54 -0700
On Sun, Sep 03, 2000 at 02:04:48AM +0000, Chris Esen wrote:
> Hey,
>
> I just spent the last hour looking over some python tutorials and I have a
> question, how can I define an array of classes or any other data type? I
> don't think a list would work for me. Let me show you what i mean in c:
>
> int myArray[5];
>
> myArray[0] = 22;
> ...
> myArray[4] = 2;
>
Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
.>>> # just like C way
.>>> myArray = [0,0,0,0,0]
.>>> myArray[0] = 22
.>>> myArray[4] = 2
.>>> print myArray
[22, 0, 0, 0, 2]
.>>> # python way
.>>> otherArray = [] # make an empty list
.>>> otherArray.append(22)
.>>> otherArray.append(0)
.>>> otherArray.append(0)
.>>> otherArray.append(0)
.>>> otherArray.append(2)
.>>> print otherArray
[22, 0, 0, 0, 2]