I'm really new to python and I'm wondering how to declare an array in this language? I can't find any reference to arrays in the docs.
+7
A:
variable = []
Now variable refers to an empty list (array).
Of course this is an assignment, not a declaration. There's no way to say in python "this variable should never refer to anything other than an array", since python is dynamically typed.
sepp2k
2009-10-03 19:07:12
+4
A:
You don't declare anything in Python. You just use it. I recommend you start out with something like http://diveintopython.org.
bayer
2009-10-03 19:08:05
+2
A:
I would normally just do a = [1,2,3] which is actually a list but for arrays look at this formal definition
non sequitor
2009-10-03 19:09:13
+3
A:
You don't actually declare things, but this is how you create an array in Python:
from array import array
intarray = array('i')
For more info see the array module: http://docs.python.org/library/array.html
Now possible you don't want an array, but a list, but others have answered that already. :)
Lennart Regebro
2009-10-03 19:44:18
This is sort of funny, but not really a good answer for a question tagged "beginner". Just to make it clear: In Python you usually use a data type called a `list`. Python has a special-purpose data type called an `array` which is more like a C array and is little used.
steveha
2009-10-04 02:48:06
No, but everyone else already used a list. I thought it would be a good answer to point out that there are arrays too.
Lennart Regebro
2009-10-04 07:38:31