liveBook · Manning

Translate

str.translate is a Python string method that returns a copy with characters transformed or deleted according to a translation table.

How 2 Manning books explain it

The Quick Python Book, Fourth Edition

translate is a Python string method that returns a copy of a string with characters transformed or removed according to a translation table.

How it is used
Normalizes text and performs coordinated character substitutions or removals before splitting, counting, or writing words.
How deep it goes
Explains translation tables, positional mappings, removal, immutability, and loop efficiency through compact runnable examples.
Examples
Uses operator conversion, punctuation removal, word normalization, and cleaning the Moby-Dick text file.
What you can do after
Apply it via Python string methods to transform or remove many characters efficiently in text-processing pipelines.

Read how The Quick Python Book, Fourth Edition explains translate →

Tiny Python Projects: Learn coding and testing with puzzles and games

str.translate() is a Python string method that returns a new string by mapping characters according to a translation table.

How it is used
Maps characters in strings for compact, one-pass substitutions while preserving characters absent from the translation table.
How deep it goes
Defines translation tables, Unicode ordinal mappings, replacement strings, deletion with None, and lookup behavior.
Examples
Demonstrates encoding phone-like digit strings while leaving letters, spaces, hyphens, and equals signs unchanged.
What you can do after
Apply it via str.maketrans() and str.translate() to build reusable character-substitution transformations.

Read how Tiny Python Projects: Learn coding and testing with puzzles and games explains translate →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.