From c036e594daba74b6a48369d63cad44bf231a13ae Mon Sep 17 00:00:00 2001 From: Blaise Pabon Date: Fri, 13 Jun 2025 11:32:07 +0000 Subject: [PATCH] gh-106318: Add example for `str.encode()` (GH-134520) (cherry picked from commit 273459562e3eaee4dd242fe8ee098cfdb4eebe9b) Co-authored-by: Blaise Pabon Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/library/stdtypes.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a3c54274597984..a32dee4ca5727e 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1705,6 +1705,14 @@ expression support in the :mod:`re` module). unless an encoding error actually occurs, :ref:`devmode` is enabled or a :ref:`debug build ` is used. + For example:: + + >>> encoded_str_to_bytes = 'Python'.encode() + >>> type(encoded_str_to_bytes) + + >>> encoded_str_to_bytes + b'Python' + .. versionchanged:: 3.1 Added support for keyword arguments.