@@ -79,14 +79,16 @@ The module defines the following type:
7979.. class :: array(typecode[, initializer])
8080
8181 A new array whose items are restricted by *typecode *, and initialized
82- from the optional *initializer * value, which must be a list, a
83- :term: ` bytes-like object`, or iterable over elements of the
84- appropriate type.
82+ from the optional *initializer * value, which must be a :class: ` bytes `
83+ or :class: ` bytearray ` object, a Unicode string, or iterable over elements
84+ of the appropriate type.
8585
86- If given a list or string, the initializer is passed to the new array's
87- :meth: `fromlist `, :meth: `frombytes `, or :meth: `fromunicode ` method (see below)
88- to add initial items to the array. Otherwise, the iterable initializer is
89- passed to the :meth: `extend ` method.
86+ If given a :class: `bytes ` or :class: `bytearray ` object, the initializer
87+ is passed to the new array's :meth: `frombytes ` method;
88+ if given a Unicode string, the initializer is passed to the
89+ :meth: `fromunicode ` method;
90+ otherwise, the initializer's iterator is passed to the :meth: `extend ` method
91+ to add initial items to the array.
9092
9193 Array objects support the ordinary sequence operations of indexing, slicing,
9294 concatenation, and multiplication. When using slice assignment, the assigned
@@ -152,10 +154,11 @@ The module defines the following type:
152154 must be the right type to be appended to the array.
153155
154156
155- .. method :: frombytes(s )
157+ .. method :: frombytes(buffer )
156158
157- Appends items from the string, interpreting the string as an array of machine
158- values (as if it had been read from a file using the :meth: `fromfile ` method).
159+ Appends items from the :term: `bytes-like object `, interpreting
160+ its content as an array of machine values (as if it had been read
161+ from a file using the :meth: `fromfile ` method).
159162
160163 .. versionadded :: 3.2
161164 :meth: `!fromstring ` is renamed to :meth: `frombytes ` for clarity.
@@ -177,7 +180,7 @@ The module defines the following type:
177180
178181 .. method :: fromunicode(s)
179182
180- Extends this array with data from the given unicode string.
183+ Extends this array with data from the given Unicode string.
181184 The array must have type code ``'u' `` or ``'w' ``; otherwise a :exc: `ValueError ` is raised.
182185 Use ``array.frombytes(unicodestring.encode(enc)) `` to append Unicode data to an
183186 array of some other type.
@@ -239,24 +242,27 @@ The module defines the following type:
239242
240243 .. method :: tounicode()
241244
242- Convert the array to a unicode string. The array must have a type ``'u' `` or ``'w' ``;
245+ Convert the array to a Unicode string. The array must have a type ``'u' `` or ``'w' ``;
243246 otherwise a :exc: `ValueError ` is raised. Use ``array.tobytes().decode(enc) `` to
244- obtain a unicode string from an array of some other type.
247+ obtain a Unicode string from an array of some other type.
245248
246249
247- When an array object is printed or converted to a string, it is represented as
248- ``array(typecode, initializer) ``. The *initializer * is omitted if the array is
249- empty, otherwise it is a string if the *typecode * is ``'u' `` or ``'w' ``,
250- otherwise it is a list of numbers.
251- The string is guaranteed to be able to be converted back to an
250+ The string representation of array objects has the form
251+ ``array(typecode, initializer) ``.
252+ The *initializer * is omitted if the array is empty, otherwise it is
253+ a Unicode string if the *typecode * is ``'u' `` or ``'w' ``, otherwise it is
254+ a list of numbers.
255+ The string representation is guaranteed to be able to be converted back to an
252256array with the same type and value using :func: `eval `, so long as the
253257:class: `~array.array ` class has been imported using ``from array import array ``.
258+ Variables ``inf `` and ``nan `` must also be defined if it contains
259+ corresponding floating point values.
254260Examples::
255261
256262 array('l')
257263 array('w', 'hello \u2641')
258264 array('l', [1, 2, 3, 4, 5])
259- array('d', [1.0, 2.0, 3.14])
265+ array('d', [1.0, 2.0, 3.14, -inf, nan ])
260266
261267
262268.. seealso ::
0 commit comments