From eaed43c52ada2b88a98d37500e596799339f9a63 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Thu, 9 Apr 2026 14:33:31 +0100 Subject: [PATCH] gh-106318: Add example for str.swapcase() method (GH-144575) (cherry picked from commit d11e9ff8ca0e6fc5525a47eeb0e99637987bb385) Co-authored-by: Adorilson Bezerra --- Doc/library/stdtypes.rst | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index be1ef1a1d1c6ca..37b940a07e6cc0 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2771,8 +2771,22 @@ expression support in the :mod:`re` module). .. method:: str.swapcase() Return a copy of the string with uppercase characters converted to lowercase and - vice versa. Note that it is not necessarily true that - ``s.swapcase().swapcase() == s``. + vice versa. For example: + + .. doctest:: + + >>> 'Hello World'.swapcase() + 'hELLO wORLD' + + Note that it is not necessarily true that ``s.swapcase().swapcase() == s``. + For example: + + .. doctest:: + + >>> 'straße'.swapcase().swapcase() + 'strasse' + + See also :meth:`str.lower` and :meth:`str.upper`. .. method:: str.title()