{"id":3727,"date":"2022-12-02T18:54:34","date_gmt":"2022-12-02T18:54:34","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3727"},"modified":"2022-12-02T18:54:35","modified_gmt":"2022-12-02T18:54:35","slug":"python-string-translate","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-string-translate\/","title":{"rendered":"Python String translate() Method With Example"},"content":{"rendered":"<p style=\"text-align: center;\">Python String translate<\/p>\n<p>Now, we are going to learn about the translate method. Using this method, we get a copy of the string, where each character is mapped to its corresponding character in the translation table. We can say that the translate method takes a translation table, and according to the mapping table, it replaces (or translates) the characters in the given string. Let\u2019s have a look at a simple example, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3728 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-translate-METHOD.jpg\" alt=\"\" width=\"627\" height=\"131\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-translate-METHOD.jpg 627w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-translate-METHOD-300x63.jpg 300w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python String translate() Method<\/h2>\n<p>As you can see in the above program, we have two strings, and then we are creating a mapping table, using the maketrans method, and then calling the translate method on the first string. We pass the table as an argument. The return string from the translate method is returned to the newstring method, and then we are printing the string1 and the newstring.<\/p>\n<p>In the returned string, you can find that the characters are mapped to their corresponding characters from the mapping characters. Let\u2019s have a look at the output now.<\/p>\n<p>ABCDEFGHIJK<\/p>\n<p>GyaniPandit<\/p>\n<p>As you can see in the output, each character from the string is mapped with the corresponding character in the mapping table.<\/p>\n<p>So, as and when required, we can make use of the translate method. With the translate method, we get a copy of the string, where each character of the string is mapped to the corresponding character in the mapping table.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python String translate Now, we are going to learn about the translate method. Using this method, we get a copy of the string, where each character is mapped to its corresponding character in the translation table. We can say that the translate method takes a translation table, and according to the mapping table, it replaces [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3727","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3727"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3727\/revisions"}],"predecessor-version":[{"id":4201,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3727\/revisions\/4201"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}