Skip to content
Open
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
6 changes: 6 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,12 @@ 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'``::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use .. doctest:: here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other examples in stdtypes.rst (e.g. the str.title() example just above) consistently use :: with >>> prompts rather than .. doctest::. I kept the same style for consistency. Would you still prefer .. doctest:: here?


>>> '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