99--------------
1010
1111This module defines an object type which can compactly represent an array of
12- basic values: characters, integers, floating-point numbers. Arrays are mutable :term: `sequence `
12+ basic values: characters, integers, floating-point numbers, complex numbers . Arrays are mutable :term: `sequence `
1313types and behave very much like lists, except that the type of objects stored in
1414them is constrained. The type is specified at object creation time by using a
1515:dfn: `type code `, which is a single character. The following type codes are
@@ -46,6 +46,11 @@ defined:
4646+-----------+--------------------+-------------------+-----------------------+-------+
4747| ``'d' `` | double | float | 8 | |
4848+-----------+--------------------+-------------------+-----------------------+-------+
49+ | ``'F' `` | float complex | complex | 8 | \( 3) |
50+ +-----------+--------------------+-------------------+-----------------------+-------+
51+ | ``'D' `` | double complex | complex | 16 | \( 3) |
52+ +-----------+--------------------+-------------------+-----------------------+-------+
53+
4954
5055Notes:
5156
@@ -63,6 +68,15 @@ Notes:
6368(2)
6469 .. versionadded :: 3.13
6570
71+ (3)
72+ Complex types (``F `` and ``D ``) are available unconditionally,
73+ regardless on support for complex types (the Annex G of the C11 standard)
74+ by the C compiler.
75+ As specified in the C11 standard, each complex type is represented by a
76+ two-element C array containing, respectively, the real and imaginary parts.
77+
78+ .. versionadded :: 3.15
79+
6680.. seealso ::
6781
6882 The :ref: `ctypes <ctypes-fundamental-data-types >` and
@@ -119,9 +133,9 @@ The module defines the following type:
119133 The length in bytes of one array item in the internal representation.
120134
121135
122- .. method :: append(x )
136+ .. method :: append(value, / )
123137
124- Append a new item with value * x * to the end of the array.
138+ Append a new item with the specified value to the end of the array.
125139
126140
127141 .. method :: buffer_info()
@@ -146,25 +160,26 @@ The module defines the following type:
146160 .. method :: byteswap()
147161
148162 "Byteswap" all items of the array. This is only supported for values which are
149- 1, 2, 4, or 8 bytes in size; for other types of values, :exc: `RuntimeError ` is
163+ 1, 2, 4, 8 or 16 bytes in size; for other types of values, :exc: `RuntimeError ` is
150164 raised. It is useful when reading data from a file written on a machine with a
151- different byte order.
165+ different byte order. Note, that for complex types the order of
166+ components (the real part, followed by imaginary part) is preserved.
152167
153168
154- .. method :: count(x )
169+ .. method :: count(value, / )
155170
156- Return the number of occurrences of *x * in the array.
171+ Return the number of occurrences of *value * in the array.
157172
158173
159- .. method :: extend(iterable)
174+ .. method :: extend(iterable, / )
160175
161176 Append items from *iterable * to the end of the array. If *iterable * is another
162177 array, it must have *exactly * the same type code; if not, :exc: `TypeError ` will
163178 be raised. If *iterable * is not an array, it must be iterable and its elements
164179 must be the right type to be appended to the array.
165180
166181
167- .. method :: frombytes(buffer)
182+ .. method :: frombytes(buffer, / )
168183
169184 Appends items from the :term: `bytes-like object `, interpreting
170185 its content as an array of machine values (as if it had been read
@@ -174,55 +189,55 @@ The module defines the following type:
174189 :meth: `!fromstring ` is renamed to :meth: `frombytes ` for clarity.
175190
176191
177- .. method :: fromfile(f, n)
192+ .. method :: fromfile(f, n, / )
178193
179194 Read *n * items (as machine values) from the :term: `file object ` *f * and append
180195 them to the end of the array. If less than *n * items are available,
181196 :exc: `EOFError ` is raised, but the items that were available are still
182197 inserted into the array.
183198
184199
185- .. method :: fromlist(list)
200+ .. method :: fromlist(list, / )
186201
187202 Append items from the list. This is equivalent to ``for x in list:
188203 a.append(x) `` except that if there is a type error, the array is unchanged.
189204
190205
191- .. method :: fromunicode(s )
206+ .. method :: fromunicode(ustr, / )
192207
193208 Extends this array with data from the given Unicode string.
194209 The array must have type code ``'u' `` or ``'w' ``; otherwise a :exc: `ValueError ` is raised.
195210 Use ``array.frombytes(unicodestring.encode(enc)) `` to append Unicode data to an
196211 array of some other type.
197212
198213
199- .. method :: index(x [, start[, stop]])
214+ .. method :: index(value [, start[, stop]])
200215
201216 Return the smallest *i * such that *i * is the index of the first occurrence of
202- *x * in the array. The optional arguments *start * and *stop * can be
203- specified to search for *x * within a subsection of the array. Raise
204- :exc: `ValueError ` if *x * is not found.
217+ *value * in the array. The optional arguments *start * and *stop * can be
218+ specified to search for *value * within a subsection of the array. Raise
219+ :exc: `ValueError ` if *value * is not found.
205220
206221 .. versionchanged :: 3.10
207222 Added optional *start * and *stop * parameters.
208223
209224
210- .. method :: insert(i, x )
225+ .. method :: insert(index, value, / )
211226
212- Insert a new item with value * x * in the array before position *i *. Negative
227+ Insert a new item * value * in the array before position *index *. Negative
213228 values are treated as being relative to the end of the array.
214229
215230
216- .. method :: pop([i] )
231+ .. method :: pop(index=-1, / )
217232
218233 Removes the item with the index *i * from the array and returns it. The optional
219234 argument defaults to ``-1 ``, so that by default the last item is removed and
220235 returned.
221236
222237
223- .. method :: remove(x )
238+ .. method :: remove(value, / )
224239
225- Remove the first occurrence of *x * from the array.
240+ Remove the first occurrence of *value * from the array.
226241
227242
228243 .. method :: clear()
@@ -247,7 +262,7 @@ The module defines the following type:
247262 :meth: `!tostring ` is renamed to :meth: `tobytes ` for clarity.
248263
249264
250- .. method :: tofile(f)
265+ .. method :: tofile(f, / )
251266
252267 Write all items (as machine values) to the :term: `file object ` *f *.
253268
0 commit comments