String maketrans() Method
时间:2010-01-18 来源:angelia_liu
Python String maketrans() Method
Description:
This method returns a translation table that maps each character in the intab string into the character at the same position in the outtab string. Then this table is passed to the translate() function. Note that both intab and outtab must have the same length.
Syntax:
str.maketrans(intab, outtab]); |
Parameters:
Here is the detail of parameters:
-
intab: string having actual characters.
-
outtab: string having corresponding mapping character.
Return Value:
It returns a translate table to be used translate() function.
Example:
This example every vowel in a string is replaced by its vowel position:
#!/usr/bin/python |
This will produce following result:
th3s 3s str3ng 2x1mpl2....w4w!!!
相关阅读 更多 +