中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

Python translate()方法

Python 字符串 Python 字符串


描述

Python translate() 方法根據(jù)參數(shù)table給出的表(包含 256 個(gè)字符)轉(zhuǎn)換字符串的字符, 要過(guò)濾掉的字符放到 del 參數(shù)中。

語(yǔ)法

translate()方法語(yǔ)法:

str.translate(table[, deletechars]);

參數(shù)

  • table -- 翻譯表,翻譯表是通過(guò)maketrans方法轉(zhuǎn)換而來(lái)。
  • deletechars -- 字符串中要過(guò)濾的字符列表。

返回值

返回翻譯后的字符串。

實(shí)例

以下實(shí)例展示了 translate()函數(shù)的使用方法:

實(shí)例(Python 2.0+)

#!/usr/bin/python from string import maketrans # 引用 maketrans 函數(shù)。 intab = "aeiou" outtab = "12345" trantab = maketrans(intab, outtab) str = "this is string example....wow!!!"; print str.translate(trantab);

以上實(shí)例輸出結(jié)果如下:

th3s 3s str3ng 2x1mpl2....w4w!!!

以上實(shí)例去除字符串中的 'x' 和 'm' 字符:

實(shí)例(Python 2.0+)

#!/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, 'xm');

以上實(shí)例輸出結(jié)果:

th3s 3s str3ng 21pl2....w4w!!!

Python 字符串 Python 字符串

其他擴(kuò)展