[Tutor] dynamic arrays?

Steven D'Aprano steve at pearwood.info
Mon Sep 27 19:49:50 CEST 2010


On Tue, 28 Sep 2010 01:45:56 am Brian Jones wrote:

> A python list and a python array are one and the same to my
> knowledge.

Close, but not quite.

Python has an array type. It is almost identical to lists, except the 
type of data it will hold is constrained to a specific type:

>>> import array
>>> a = array.array('i')
>>> a.append(42)
>>> a
array('i', [42])
>>> a.append("spam")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required



-- 
Steven D'Aprano


More information about the Tutor mailing list