From 28df2630edf32313184eeaa74c7fb693b4d407eb Mon Sep 17 00:00:00 2001 From: Daniil Mayorov Date: Tue, 19 May 2026 16:44:39 +0300 Subject: [PATCH] gh-72798: Add example to str.translate documentation --- Doc/library/stdtypes.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index e3bd1a46891adc..bab18ce9a7afc8 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2851,6 +2851,14 @@ expression support in the :mod:`re` module). >>> 'abc123'.translate({ord('a'): 'X', ord('b'): 'Y', ord('c'): None}) 'XY123' + For example, removing vowels using :meth:`str.maketrans`: + + .. doctest:: + + >>> table = str.maketrans('', '', 'aeiou') + >>> 'hello world'.translate(table) + 'hll wrld' + See also the :mod:`codecs` module for a more flexible approach to custom character mappings.