Hướng dẫn hàm translate trong python
Show The translation table is created by the static method maketrans(). The syntax of the string.translate(table) String translate() Parameters
Return value from String translate()
Example 1: Translation/Mapping using a translation table with translate()
Output Original string: abcdef Translated string: idef Here, the translation mapping translation contains the mapping from 0 to 1 respectively.But, the removal string thirdString resets the mapping to 2 and 3 to 4.So, when the string is translated using 2 and 3 are removed, and 8 is replaced 9 outputting Original string: abcdef Translated string: idef0. Note: If you cannot understand what's going inside maketrans(), please refer to String maketrans(). Example 2: Translation/Mapping with translate() with manual translation table
Output Original string: abcdef Translated string: idef Here, we don't create a translation table from This translation is then used to translate Original string: abcdef Translated string: idef2 to get the same output as the previous example. |