文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>String maketrans() Method

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

from string import maketrans # Required to call maketrans function.

intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)

str = "this is string example....wow!!!";
print str.translate(trantab);

This will produce following result:

th3s 3s str3ng 2x1mpl2....w4w!!!
相关阅读 更多 +
排行榜 更多 +
船舶模拟器无限金币

船舶模拟器无限金币

休闲益智 下载
我的兵与城(内置功能菜单)

我的兵与城(内置功能菜单)

休闲益智 下载
挑战烧脑免广告版

挑战烧脑免广告版

休闲益智 下载