Skip to content

Commit 28df263

Browse files
committed
gh-72798: Add example to str.translate documentation
1 parent 00ea776 commit 28df263

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,14 @@ expression support in the :mod:`re` module).
28512851
>>> 'abc123'.translate({ord('a'): 'X', ord('b'): 'Y', ord('c'): None})
28522852
'XY123'
28532853

2854+
For example, removing vowels using :meth:`str.maketrans`:
2855+
2856+
.. doctest::
2857+
2858+
>>> table = str.maketrans('', '', 'aeiou')
2859+
>>> 'hello world'.translate(table)
2860+
'hll wrld'
2861+
28542862
See also the :mod:`codecs` module for a more flexible approach to custom
28552863
character mappings.
28562864

0 commit comments

Comments
 (0)