文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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!!!
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载