array — 高效数值数组


This module defines an object type which can compactly represent an array of basic values: characters, integers, floating-point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained. The type is specified at object creation time by using a type code , which is a single character. The following type codes are defined:

类型代码

C 类型

Python 类型

Minimum size in bytes

注意事项

'b'

signed char

int

1

'B'

unsigned char

int

1

'u'

wchar_t

Unicode 字符

2

(1)

'w'

Py_UCS4

Unicode 字符

4

'h'

signed short

int

2

'H'

unsigned short

int

2

'i'

signed int

int

2

'I'

无符号 int

int

2

'l'

signed long

int

4

'L'

unsigned long

int

4

'q'

signed long long

int

8

'Q'

unsigned long long

int

8

'f'

float

float

4

'd'

double

float

8

注意事项:

  1. 它可以是 16 位 (或 32 位) 从属平台。

    3.9 版改变: array('u') 现在使用 wchar_t as C type instead of deprecated Py_UNICODE . This change doesn’t affect its behavior because Py_UNICODE is alias of wchar_t since Python 3.3.

    Deprecated since version 3.3, will be removed in version 3.16: Please migrate to 'w' typecode.