]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Add example for `str.encode()` (#134520)
authorBlaise Pabon <blaise@gmail.com>
Fri, 13 Jun 2025 11:32:07 +0000 (11:32 +0000)
committerGitHub <noreply@github.com>
Fri, 13 Jun 2025 11:32:07 +0000 (11:32 +0000)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Doc/library/stdtypes.rst

index b75e5ceecf874e8c6efa484d5d1f66180c131190..4854a2c077bb2833b93f9f4ce9af92f20cbc5016 100644 (file)
@@ -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 <debug-build>` is used.
+   For example::
+
+      >>> encoded_str_to_bytes = 'Python'.encode()
+      >>> type(encoded_str_to_bytes)
+      <class 'bytes'>
+      >>> encoded_str_to_bytes
+      b'Python'
+
 
    .. versionchanged:: 3.1
       Added support for keyword arguments.