Skip to content

Commit f15ead9

Browse files
committed
gh-106318: Add example for str.maketrans()
1 parent 1cc7551 commit f15ead9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Doc/library/stdtypes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,11 +2316,25 @@ expression support in the :mod:`re` module).
23162316
strings (of arbitrary lengths) or ``None``. Character keys will then be
23172317
converted to ordinals.
23182318

2319+
For example:
2320+
2321+
.. doctest::
2322+
2323+
>>> str.maketrans({'a': 'A', 'b': 'Boo', 'c': None})
2324+
{97: 'A', 98: 'Boo', 99: None}
2325+
23192326
If there are two arguments, they must be strings of equal length, and in the
23202327
resulting dictionary, each character in *from* will be mapped to the character at
23212328
the same position in *to*. If there is a third argument, it must be a string,
23222329
whose characters will be mapped to ``None`` in the result.
23232330

2331+
For example:
2332+
2333+
.. doctest::
2334+
2335+
>>> str.maketrans('ab', 'AB', 'c')
2336+
{97: 65, 98: 66, 99: None}
2337+
23242338

23252339
.. method:: str.partition(sep, /)
23262340

0 commit comments

Comments
 (0)