Skip to content

Commit 2326a79

Browse files
committed
Add a warning text about mixing bytes and strings.
1 parent 37f1038 commit 2326a79

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ constructed from literals too; use a ``b`` prefix with normal string syntax:
515515
object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be a bytes
516516
object of length 1.
517517

518+
Also, while in previous Python versions, byte strings and Unicode strings
519+
could be exchanged for each other rather freely (barring encoding issues),
520+
strings and bytes are completely separate concepts. There's no implicit
521+
en-/decoding if you pass and object of the wrong type or try to e.g. compare
522+
a string with a bytes object.
523+
518524
Lists are constructed with square brackets, separating items with commas: ``[a,
519525
b, c]``. Tuples are constructed by the comma operator (not within square
520526
brackets), with or without enclosing parentheses, but an empty tuple must have

0 commit comments

Comments
 (0)