Python string translate() method
Replace or delete many single characters at once.
Syntax
str.translate(table)
Build the table with str.maketrans. Faster and shorter than many replace calls.
Parameters
| table | made with str.maketrans(from, to, delete) |
Return value
str
Example
Code
table = str.maketrans("aeiou", "AEIOU") print("education".translate(table)) no_punct = str.maketrans("", "", ",.!?") print("Hello, world! Ready?".translate(no_punct))
Output
EdUcAtIOn Hello world Ready
Related
Learn it step by step in the free lesson Strings, with exercises that check your answers.