[Tutor] array('c')

Peter Otten __peter__ at web.de
Thu May 1 17:35:22 CEST 2014


Ian D wrote:

> I have this part of code and am unsure as to the effect of the array('c')
> part. Is it creating an array and adding 'c' as its first value?

No, the first arg to array.array() is the typecode; data may be passed as 
the second argument. The typecode "c" creates an array of 8-bit characters 
as defined by the C compiler.

>>> a = array.array("c")
>>> len(a)
0
>>> a = array.array("c", "abc")
>>> len(a)
3

See <https://docs.python.org/2.7/library/array.html> for more.





More information about the Tutor mailing list