Index: Doc/library/functions.rst =================================================================== --- Doc/library/functions.rst (revision 79936) +++ Doc/library/functions.rst (working copy) @@ -62,6 +62,44 @@ .. versionadded:: 2.6 +.. function:: bytearray([source[, encoding[, errors]]]) + + Return a new array of bytes. The :class:`bytearray` type is a mutable + sequence of integers in the range 0 <= x < 256. It has most of the usual + methods of mutable sequences, described in :ref:`typesseq-mutable`, as well + as most methods that the :class:`str` type has, see :ref:`bytes-methods`. + + The optional *source* parameter can be used to initialize the array in a few + different ways: + + * If it is a *string*, you must also give the *encoding* (and optionally, + *errors*) parameters; :func:`bytearray` then converts the string to + bytes using :meth:`str.encode`. + + * If it is an *integer*, the array will have that size and will be + initialized with null bytes. + + * If it is an object conforming to the *buffer* interface, a read-only buffer + of the object will be used to initialize the bytes array. + + * If it is an *iterable*, it must be an iterable of integers in the range + ``0 <= x < 256``, which are used as the initial contents of the array. + + Without an argument, an array of size 0 is created. + + +.. function:: bytes([source[, encoding[, errors]]]) + + Return a new "bytes" object, which is an immutable sequence of integers in + the range ``0 <= x < 256``. :class:`bytes` is an immutable version of + :class:`bytearray` -- it has the same non-mutating methods and the same + indexing and slicing behavior. + + Accordingly, constructor arguments are interpreted as for :func:`bytearray`. + + Bytes objects can also be created with literals, see :ref:`strings`. + + .. function:: bool([x]) Convert a value to a Boolean, using the standard truth testing procedure. If