PyDocs

Nav

Python Runtime Services

str.translate

builtins

method of str
  • str.translate(table, /)
Replace each character in the string using the given translation table.

  table
    Translation table, which must be a mapping of Unicode ordinals
    to Unicode ordinals, strings, or None.

The table must implement lookup/indexing via __getitem__, for
instance a dictionary or list.  If this operation raises
LookupError, the character is left untouched.  Characters mapped to
None are deleted.
1 Example
>>> 'abc123'.translate({ord('a'): 'X', ord('b'): 'Y', ord('c'): None})
'XY123'
from the Python docs
See Also
No see-alsos for builtins/str.translate
0 Notes
No notes for str.translate