Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,14 @@ expression support in the :mod:`re` module).
You can use :meth:`str.maketrans` to create a translation map from
character-to-character mappings in different formats.

The following example uses a mapping to replace ``'a'`` with ``'X'``,
``'b'`` with ``'Y'``, and delete ``'c'``:

.. doctest::

>>> 'abc123'.translate({ord('a'): 'X', ord('b'): 'Y', ord('c'): None})
'XY123'

See also the :mod:`codecs` module for a more flexible approach to custom
character mappings.

Expand Down
Loading