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

Python translate()方法

Python 字符串 Python 字符串


描述

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

語法

translate()方法語法:

str.translate(table[, deletechars]);

參數(shù)

  • table -- 翻譯表,翻譯表是通過maketrans方法轉換而來。
  • deletechars -- 字符串中要過濾的字符列表。

返回值

返回翻譯后的字符串。

實例

以下實例展示了 translate()函數(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);

以上實例輸出結果如下:

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

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

實例(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');

以上實例輸出結果:

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

Python 字符串 Python 字符串

其他擴展