来来去去
分类: Python/Ruby
2010-01-18 19:00:20
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.
str.maketrans(intab, outtab]); |
Here is the detail of parameters:
intab: string having actual characters.
outtab: string having corresponding mapping character.
It returns a translate table to be used translate() function.
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!!!