{"id":26074,"date":"2023-05-30T10:20:59","date_gmt":"2023-05-30T04:50:59","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=26074"},"modified":"2026-07-13T12:42:50","modified_gmt":"2026-07-13T07:12:50","slug":"python-translate","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-translate\/","title":{"rendered":"Python str.translate(): Replace, Delete, and Normalize Characters"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> Python str.translate() performs character-level mapping through a translation table; it is not natural-language translation. Build the table with str.maketrans(), map one character to another or to a longer string, and map to None to delete characters. Use str.replace() or a dedicated language library for words, phrases, and language translation.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-translate.png\" alt=\"Python Pool infographic showing str maketrans character mapping deletion and translated string output\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>str.translate maps individual characters through a translation table; use None to delete characters and choose replace() or a language library for phrase translation.<\/figcaption><\/figure>\n<p>Python <code>translate()<\/code> is a string method for character-level replacement and deletion. It does not translate English to Spanish or one natural language to another. Instead, <code>str.translate()<\/code> maps each character through a translation table, usually created with <code>str.maketrans()<\/code>.<\/p>\n<p>Use it when you need to replace many single characters at once, remove characters such as digits or punctuation, normalize simple text, or build a fast character mapping. This is character translation, not language translation. For ordinary word or phrase replacement, <code>str.replace()<\/code> is often clearer.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Basic_translate_example\" >Basic translate() example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Use_maketrans_with_two_strings\" >Use maketrans() with two strings<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Delete_characters_with_the_third_argument\" >Delete characters with the third argument<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Map_one_character_to_multiple_characters\" >Map one character to multiple characters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Remove_punctuation\" >Remove punctuation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#ROT13-style_character_mapping\" >ROT13-style character mapping<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#translate_vs_replace\" >translate() vs replace()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Common_mistakes\" >Common mistakes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Official_references\" >Official references<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Map_Characters_With_A_Dictionary\" >Map Characters With A Dictionary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Use_Equal-Length_From_And_To_Strings\" >Use Equal-Length From And To Strings<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Delete_Characters_With_None\" >Delete Characters With None<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Choose_The_Right_Text_Tool\" >Choose The Right Text Tool<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#What_does_Python_strtranslate_do\" >What does Python str.translate() do?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#How_do_I_create_a_translation_table\" >How do I create a translation table?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#How_do_I_delete_characters_with_translate\" >How do I delete characters with translate()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.pythonpool.com\/python-translate\/#Should_I_use_translate_for_words_or_phrases\" >Should I use translate() for words or phrases?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Basic_translate_example\"><\/span>Basic translate() example<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Create a translation table with <code>str.maketrans()<\/code>, then call <code>translate()<\/code> on the string.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">text = \"make text safe\"\ntable = str.maketrans({\"a\": \"@\", \"e\": \"3\", \" \": \"_\"})\n\nresult = text.translate(table)\nprint(result)<\/code><\/pre>\n<\/div>\n<p>The local Python 3.14 check returned <code>m@k3_t3xt_s@f3<\/code>. Each matching character was replaced, and characters not listed in the table stayed unchanged.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_maketrans_with_two_strings\"><\/span>Use maketrans() with two strings<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The two-string form maps characters by position. The first character in the first string maps to the first character in the second string, and so on.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">table = str.maketrans(\"ae \", \"@3_\")\nprint(\"make text safe\".translate(table))<\/code><\/pre>\n<\/div>\n<p>This produces the same result as the dictionary example. The two strings must have equal length. If they do not, Python raises <code>ValueError<\/code>. In local testing, <code>str.maketrans(\"ab\", \"x\")<\/code> raised that exact error.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/translate-maketrans-b217.png\" alt=\"Python Pool infographic showing source characters, str.maketrans, mapping, and table\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>str.maketrans creates a translation table for str.translate.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Delete_characters_with_the_third_argument\"><\/span>Delete characters with the third argument<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The third argument to <code>str.maketrans()<\/code> lists characters to remove. This is useful for stripping digits, punctuation, or other unwanted characters.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">text = \"Python 3.14\"\ndelete_digits = str.maketrans(\"\", \"\", \"0123456789.\")\n\nprint(text.translate(delete_digits))<\/code><\/pre>\n<\/div>\n<p>The result is <code>Python <\/code>, because the digits and period were deleted. If you need to clean generated file names after translation, see <a href=\"https:\/\/www.pythonpool.com\/python-get-filename-from-path\/\">getting a filename from a path in Python<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Map_one_character_to_multiple_characters\"><\/span>Map one character to multiple characters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A translation table can also map one character to a longer string. Use the dictionary form for this.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">table = str.maketrans({\"&\": \"and\", \"\u2013\": \"-\"})\ntext = \"Research & development \u2013 2026\"\n\nprint(text.translate(table))<\/code><\/pre>\n<\/div>\n<p>This can be useful for lightweight text normalization. For more complex text processing, combine it with clear string-building patterns from <a href=\"https:\/\/www.pythonpool.com\/append-strings-python\/\">appending strings in Python<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Remove_punctuation\"><\/span>Remove punctuation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>string<\/code> module provides <code>string.punctuation<\/code>, which can be passed as the third argument when you want to remove ASCII punctuation.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">import string\n\ntext = \"Hello, world! Ready?\"\nremove_punctuation = str.maketrans(\"\", \"\", string.punctuation)\n\nprint(text.translate(remove_punctuation))<\/code><\/pre>\n<\/div>\n<p>This returns <code>Hello world Ready<\/code>. Be careful with Unicode punctuation if your input includes non-ASCII text; <code>string.punctuation<\/code> only covers ASCII punctuation characters.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/translate-replace-b217.png\" alt=\"Python Pool infographic mapping text through translate table to replacement characters\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>translate replaces mapped characters in a single pass over the string.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"ROT13-style_character_mapping\"><\/span>ROT13-style character mapping<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>translate()<\/code> is also useful when you have two alphabets of equal length.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">lower = \"abcdefghijklmnopqrstuvwxyz\"\nupper = lower.upper()\nrot13 = str.maketrans(\n    lower + upper,\n    lower[13:] + lower[:13] + upper[13:] + upper[:13],\n)\n\nprint(\"Python\".translate(rot13))<\/code><\/pre>\n<\/div>\n<p>The local check returned <code>Clguba<\/code>. This example is mainly a demonstration of positional mapping; do not use ROT13 for security.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"translate_vs_replace\"><\/span>translate() vs replace()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>replace()<\/code> when replacing one substring or a small number of clear phrases. Use <code>translate()<\/code> when many single-character replacements or deletions should happen in one pass.<\/p>\n<div class=\"pythonpool-table-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<table>\n<thead>\n<tr>\n<th>Task<\/th>\n<th>Better method<\/th>\n<th>Reason<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Replace one word<\/td>\n<td><code>replace()<\/code><\/td>\n<td>Clearer for substrings.<\/td>\n<\/tr>\n<tr>\n<td>Map many characters<\/td>\n<td><code>translate()<\/code><\/td>\n<td>One table handles all mappings.<\/td>\n<\/tr>\n<tr>\n<td>Delete many characters<\/td>\n<td><code>translate()<\/code><\/td>\n<td>Use <code>None<\/code> or the third <code>maketrans()<\/code> argument.<\/td>\n<\/tr>\n<tr>\n<td>Translate human languages<\/td>\n<td>External API or model<\/td>\n<td><code>str.translate()<\/code> does not do language translation.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>If you are working with user-provided text, validate it first. The guides to <a href=\"https:\/\/www.pythonpool.com\/python-user-input\/\">Python user input<\/a>, <a href=\"https:\/\/www.pythonpool.com\/python-inline-if\/\">Python inline if<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/python-ternary\/\">Python ternary expressions<\/a> cover related control-flow patterns.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/translate-delete-b217.png\" alt=\"Python Pool infographic comparing a translation table, None mapping, deleted characters, and text\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Map a character to None when it should be removed from the translated result.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Common_mistakes\"><\/span>Common mistakes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The biggest mistake is expecting <code>str.translate()<\/code> to convert text between languages. It only maps characters. For language translation, use a dedicated translation service, library, or model.<\/p>\n<p>Another common mistake is passing two strings of different lengths to <code>str.maketrans()<\/code>. Those strings must match length because characters are paired by position. If you need deletion, use the third argument or map characters to <code>None<\/code> in a dictionary.<\/p>\n<p>Finally, remember that strings are immutable. <code>translate()<\/code> returns a new string; it does not modify the original string in place. If you need to confirm your interpreter version while testing examples, see <a href=\"https:\/\/www.pythonpool.com\/how-to-check-python-version\/\">how to check your Python version<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Official_references\"><\/span>Official references<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The examples here follow the Python documentation for <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str.translate\">str.translate()<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str.maketrans\">str.maketrans()<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str.replace\">str.replace()<\/a>, and <a href=\"https:\/\/docs.python.org\/3\/library\/string.html#string.punctuation\">string.punctuation<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use Python <code>translate()<\/code> for character-level mapping, replacement, expansion, and deletion. Build the table with <code>str.maketrans()<\/code>, use <code>replace()<\/code> for simple substrings, and choose a separate translation API when the goal is human-language translation.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Map_Characters_With_A_Dictionary\"><\/span>Map Characters With A Dictionary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The dictionary form of maketrans accepts single-character keys and values such as strings, integer code points, or None. Characters not present in the table pass through unchanged.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">text = \"make text safe\"\ntable = str.maketrans({\"a\": \"@\", \"e\": \"3\", \" \" : \"_\"})\nresult = text.translate(table)\nprint(result)\n<\/code><\/pre>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Use_Equal-Length_From_And_To_Strings\"><\/span>Use Equal-Length From And To Strings<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The two-string form maps characters by position. The strings must have equal length, so it is convenient for a small one-to-one mapping but less expressive than a dictionary for deletion or expansion.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">table = str.maketrans(\"ae \" , \"@3_\")\nprint(\"make text safe\".translate(table))\n\ntry:\n    str.maketrans(\"ab\", \"x\")\nexcept ValueError as error:\n    print(error)\n<\/code><\/pre>\n<\/div>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/translate-check-b217.png\" alt=\"Python Pool infographic testing Unicode, overlapping rules, normalization, and validation\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Check code points, mapping precedence, Unicode behavior, normalization, and output policy.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Delete_Characters_With_None\"><\/span>Delete Characters With None<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Map unwanted characters to None or pass a third string to maketrans. This is useful for a known character set such as digits or punctuation; it is not a general-purpose Unicode normalization policy.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">text = \"Python 3.14!\"\ndelete = str.maketrans(\"\", \"\", \"0123456789.!\")\nprint(text.translate(delete))\n<\/code><\/pre>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Choose_The_Right_Text_Tool\"><\/span>Choose The Right Text Tool<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>translate is efficient for many independent character substitutions. replace is clearer for a word or phrase, regular expressions fit pattern-based edits, and a translation service or language model is required for semantic language translation.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">text = \"red,green,blue\"\ncharacter_table = str.maketrans({\",\": \";\"})\nprint(text.translate(character_table))\nprint(text.replace(\"green\", \"emerald\"))\n<\/code><\/pre>\n<\/div>\n<p>Python&#8217;s official <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str.translate\">str.translate()<\/a> and <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str.maketrans\">str.maketrans()<\/a> references define character mapping, deletion with None, and the supported table forms. Related references include <a href=\"https:\/\/www.pythonpool.com\/python-trim\/\">trim methods<\/a>, <a href=\"https:\/\/www.pythonpool.com\/remove-character-from-string-python\/\">removing characters<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/python-string-length\/\">string length<\/a>.<\/p>\n<p>For related character-processing tasks, compare <a href=\"https:\/\/www.pythonpool.com\/python-trim\/\">trim methods<\/a>, <a href=\"https:\/\/www.pythonpool.com\/python-string-length\/\">string length<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/remove-character-from-string-python\/\">removing characters<\/a> before choosing a translation table.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"What_does_Python_strtranslate_do\"><\/span>What does Python str.translate() do?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It returns a copy of a string with each character mapped through a translation table; it does not translate natural language.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_create_a_translation_table\"><\/span>How do I create a translation table?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use str.maketrans() with a mapping dictionary or with equal-length from and to strings.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_delete_characters_with_translate\"><\/span>How do I delete characters with translate()?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Map characters to None or pass the characters to remove as the third argument of str.maketrans().<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Should_I_use_translate_for_words_or_phrases\"><\/span>Should I use translate() for words or phrases?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use str.replace() or a text-processing or translation library for multi-character words, phrases, or natural-language translation.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What does Python str.translate() do?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"It returns a copy of a string with each character mapped through a translation table; it does not translate natural language.\"}},{\"@type\":\"Question\",\"name\":\"How do I create a translation table?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use str.maketrans() with a mapping dictionary or with equal-length from and to strings.\"}},{\"@type\":\"Question\",\"name\":\"How do I delete characters with translate()?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Map characters to None or pass the characters to remove as the third argument of str.maketrans().\"}},{\"@type\":\"Question\",\"name\":\"Should I use translate() for words or phrases?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use str.replace() or a text-processing or translation library for multi-character words, phrases, or natural-language translation.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use Python str.translate() and str.maketrans() to replace or delete characters, normalize text, and distinguish character mapping from language translation.<\/p>\n","protected":false},"author":38,"featured_media":32169,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[5792,5794,5793,5791,5790],"class_list":["post-26074","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-python-translate-api","tag-python-translate-api-free","tag-python-translate-google","tag-python-translate-language","tag-python-translate-library","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python str.translate(): Replace, Delete, and Normalize Characters<\/title>\n<meta name=\"description\" content=\"Use Python str.translate() and str.maketrans() to replace or delete characters, normalize text, and distinguish character mapping from language translation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-translate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python str.translate(): Replace, Delete, and Normalize Characters\" \/>\n<meta property=\"og:description\" content=\"Use Python str.translate() and str.maketrans() to replace or delete characters, normalize text, and distinguish character mapping from language translation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-translate\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-30T04:50:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T07:12:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-translate.png\" \/>\n<meta name=\"author\" content=\"Namrata Gulati\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-translate.png\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Namrata Gulati\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/\"},\"author\":{\"name\":\"Namrata Gulati\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/294338f378f0853e6af4ca4a5a907ea6\"},\"headline\":\"Python str.translate(): Replace, Delete, and Normalize Characters\",\"datePublished\":\"2023-05-30T04:50:59+00:00\",\"dateModified\":\"2026-07-13T07:12:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/\"},\"wordCount\":1009,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/python-translate-str-maketrans.png\",\"keywords\":[\"python translate api\",\"python translate api free\",\"python translate google\",\"python translate language\",\"python translate library\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/\",\"name\":\"Python str.translate(): Replace, Delete, and Normalize Characters\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/python-translate-str-maketrans.png\",\"datePublished\":\"2023-05-30T04:50:59+00:00\",\"dateModified\":\"2026-07-13T07:12:50+00:00\",\"description\":\"Use Python str.translate() and str.maketrans() to replace or delete characters, normalize text, and distinguish character mapping from language translation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/python-translate-str-maketrans.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/python-translate-str-maketrans.png\",\"width\":1350,\"height\":650,\"caption\":\"Python translate str.maketrans replace remove characters\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-translate\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python str.translate(): Replace, Delete, and Normalize Characters\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pythonpool.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/pythonpool\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/294338f378f0853e6af4ca4a5a907ea6\",\"name\":\"Namrata Gulati\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/19c5e6bfbc6202d4017b79f726b2ad5e520491d67ff428a87c071afef23ecd89?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/19c5e6bfbc6202d4017b79f726b2ad5e520491d67ff428a87c071afef23ecd89?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/19c5e6bfbc6202d4017b79f726b2ad5e520491d67ff428a87c071afef23ecd89?s=96&d=wavatar&r=g\",\"caption\":\"Namrata Gulati\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python str.translate(): Replace, Delete, and Normalize Characters","description":"Use Python str.translate() and str.maketrans() to replace or delete characters, normalize text, and distinguish character mapping from language translation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/python-translate\/","og_locale":"en_US","og_type":"article","og_title":"Python str.translate(): Replace, Delete, and Normalize Characters","og_description":"Use Python str.translate() and str.maketrans() to replace or delete characters, normalize text, and distinguish character mapping from language translation.","og_url":"https:\/\/www.pythonpool.com\/python-translate\/","og_site_name":"Python Pool","article_published_time":"2023-05-30T04:50:59+00:00","article_modified_time":"2026-07-13T07:12:50+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-translate.png","type":"","width":"","height":""}],"author":"Namrata Gulati","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-translate.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Namrata Gulati","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-translate\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-translate\/"},"author":{"name":"Namrata Gulati","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/294338f378f0853e6af4ca4a5a907ea6"},"headline":"Python str.translate(): Replace, Delete, and Normalize Characters","datePublished":"2023-05-30T04:50:59+00:00","dateModified":"2026-07-13T07:12:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-translate\/"},"wordCount":1009,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-translate\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2023\/05\/python-translate-str-maketrans.png","keywords":["python translate api","python translate api free","python translate google","python translate language","python translate library"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-translate\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-translate\/","url":"https:\/\/www.pythonpool.com\/python-translate\/","name":"Python str.translate(): Replace, Delete, and Normalize Characters","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-translate\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-translate\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2023\/05\/python-translate-str-maketrans.png","datePublished":"2023-05-30T04:50:59+00:00","dateModified":"2026-07-13T07:12:50+00:00","description":"Use Python str.translate() and str.maketrans() to replace or delete characters, normalize text, and distinguish character mapping from language translation.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-translate\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-translate\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-translate\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2023\/05\/python-translate-str-maketrans.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2023\/05\/python-translate-str-maketrans.png","width":1350,"height":650,"caption":"Python translate str.maketrans replace remove characters"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-translate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Python str.translate(): Replace, Delete, and Normalize Characters"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/294338f378f0853e6af4ca4a5a907ea6","name":"Namrata Gulati","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/19c5e6bfbc6202d4017b79f726b2ad5e520491d67ff428a87c071afef23ecd89?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/19c5e6bfbc6202d4017b79f726b2ad5e520491d67ff428a87c071afef23ecd89?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/19c5e6bfbc6202d4017b79f726b2ad5e520491d67ff428a87c071afef23ecd89?s=96&d=wavatar&r=g","caption":"Namrata Gulati"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/26074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=26074"}],"version-history":[{"count":65,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/26074\/revisions"}],"predecessor-version":[{"id":41981,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/26074\/revisions\/41981"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/32169"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=26074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=26074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=26074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}