Commit f4477703 authored by Raymond Hettinger's avatar Raymond Hettinger

Put warning block in the main flow of text.

parent b82c8e5b
...@@ -804,22 +804,20 @@ constructor, :func:`bytes`, and from literals; use a ``b`` prefix with normal ...@@ -804,22 +804,20 @@ constructor, :func:`bytes`, and from literals; use a ``b`` prefix with normal
string syntax: ``b'xyzzy'``. To construct byte arrays, use the string syntax: ``b'xyzzy'``. To construct byte arrays, use the
:func:`bytearray` function. :func:`bytearray` function.
.. warning:: While string objects are sequences of characters (represented by strings of
length 1), bytes and bytearray objects are sequences of *integers* (between 0
While string objects are sequences of characters (represented by strings of and 255), representing the ASCII value of single bytes. That means that for
length 1), bytes and bytearray objects are sequences of *integers* (between 0 a bytes or bytearray object *b*, ``b[0]`` will be an integer, while
and 255), representing the ASCII value of single bytes. That means that for ``b[0:1]`` will be a bytes or bytearray object of length 1. The
a bytes or bytearray object *b*, ``b[0]`` will be an integer, while representation of bytes objects uses the literal format (``b'...'``) since it
``b[0:1]`` will be a bytes or bytearray object of length 1. The is generally more useful than e.g. ``bytes([50, 19, 100])``. You can always
representation of bytes objects uses the literal format (``b'...'``) since it convert a bytes object into a list of integers using ``list(b)``.
is generally more useful than e.g. ``bytes([50, 19, 100])``. You can always
convert a bytes object into a list of integers using ``list(b)``. Also, while in previous Python versions, byte strings and Unicode strings
could be exchanged for each other rather freely (barring encoding issues),
Also, while in previous Python versions, byte strings and Unicode strings strings and bytes are now completely separate concepts. There's no implicit
could be exchanged for each other rather freely (barring encoding issues), en-/decoding if you pass an object of the wrong type. A string always
strings and bytes are now completely separate concepts. There's no implicit compares unequal to a bytes or bytearray object.
en-/decoding if you pass an object of the wrong type. A string always
compares unequal to a bytes or bytearray object.
Lists are constructed with square brackets, separating items with commas: ``[a, Lists are constructed with square brackets, separating items with commas: ``[a,
b, c]``. Tuples are constructed by the comma operator (not within square b, c]``. Tuples are constructed by the comma operator (not within square
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment