@@ -76,14 +76,16 @@ The module defines the following type:
7676.. class :: array(typecode[, initializer])
7777
7878 A new array whose items are restricted by *typecode *, and initialized
79- from the optional *initializer * value, which must be a list, a
80- :term: ` bytes-like object`, or iterable over elements of the
81- appropriate type.
79+ from the optional *initializer * value, which must be a :class: ` bytes `
80+ or :class: ` bytearray ` object, a Unicode string, or iterable over elements
81+ of the appropriate type.
8282
83- If given a list or string, the initializer is passed to the new array's
84- :meth: `fromlist `, :meth: `frombytes `, or :meth: `fromunicode ` method (see below)
85- to add initial items to the array. Otherwise, the iterable initializer is
86- passed to the :meth: `extend ` method.
83+ If given a :class: `bytes ` or :class: `bytearray ` object, the initializer
84+ is passed to the new array's :meth: `frombytes ` method;
85+ if given a Unicode string, the initializer is passed to the
86+ :meth: `fromunicode ` method;
87+ otherwise, the initializer's iterator is passed to the :meth: `extend ` method
88+ to add initial items to the array.
8789
8890 Array objects support the ordinary sequence operations of indexing, slicing,
8991 concatenation, and multiplication. When using slice assignment, the assigned
@@ -149,10 +151,11 @@ The module defines the following type:
149151 must be the right type to be appended to the array.
150152
151153
152- .. method :: frombytes(s )
154+ .. method :: frombytes(buffer )
153155
154- Appends items from the string, interpreting the string as an array of machine
155- values (as if it had been read from a file using the :meth: `fromfile ` method).
156+ Appends items from the :term: `bytes-like object `, interpreting
157+ its content as an array of machine values (as if it had been read
158+ from a file using the :meth: `fromfile ` method).
156159
157160 .. versionadded :: 3.2
158161 :meth: `!fromstring ` is renamed to :meth: `frombytes ` for clarity.
@@ -174,9 +177,9 @@ The module defines the following type:
174177
175178 .. method :: fromunicode(s)
176179
177- Extends this array with data from the given unicode string. The array must
178- be a type ``'u' `` array ; otherwise a :exc: `ValueError ` is raised. Use
179- ``array.frombytes(unicodestring.encode(enc)) `` to append Unicode data to an
180+ Extends this array with data from the given Unicode string.
181+ The array must have type code ``'u' ``; otherwise a :exc: `ValueError ` is raised.
182+ Use ``array.frombytes(unicodestring.encode(enc)) `` to append Unicode data to an
180183 array of some other type.
181184
182185
@@ -236,23 +239,27 @@ The module defines the following type:
236239
237240 .. method :: tounicode()
238241
239- Convert the array to a unicode string. The array must be a type ``'u' `` array ;
242+ Convert the array to a Unicode string. The array must have a type ``'u' ``;
240243 otherwise a :exc: `ValueError ` is raised. Use ``array.tobytes().decode(enc) `` to
241- obtain a unicode string from an array of some other type.
244+ obtain a Unicode string from an array of some other type.
242245
243246
244- When an array object is printed or converted to a string, it is represented as
245- ``array(typecode, initializer) ``. The *initializer * is omitted if the array is
246- empty, otherwise it is a string if the *typecode * is ``'u' ``, otherwise it is a
247- list of numbers. The string is guaranteed to be able to be converted back to an
247+ The string representation of array objects has the form
248+ ``array(typecode, initializer) ``.
249+ The *initializer * is omitted if the array is empty, otherwise it is
250+ a Unicode string if the *typecode * is ``'u' ``, otherwise it is
251+ a list of numbers.
252+ The string representation is guaranteed to be able to be converted back to an
248253array with the same type and value using :func: `eval `, so long as the
249254:class: `~array.array ` class has been imported using ``from array import array ``.
255+ Variables ``inf `` and ``nan `` must also be defined if it contains
256+ corresponding floating point values.
250257Examples::
251258
252259 array('l')
253260 array('u', 'hello \u2641')
254261 array('l', [1, 2, 3, 4, 5])
255- array('d', [1.0, 2.0, 3.14])
262+ array('d', [1.0, 2.0, 3.14, -inf, nan ])
256263
257264
258265.. seealso ::
0 commit comments