From 1876fff34d5e1cc31a51c25299ea79538eb12d2d 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 b75e5ceecf874e..4854a2c077bb28 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1841,6 +1841,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.