当前位置:首页 > 热点

云计算开发:Python3-translate()方法详解

描述

Python translate() 方法根据参数tab云计le给出的表(包含 256 个字符)转换字符串的字符,要过滤掉的算开字符放到 deletechars 参数中。

语法

以下是 transla发:te() 方法语法:

str.translate(table)

byPytes.translate(table[, delete]th)    

bytearray.translatone(table[, delete]) 

参数

tabl3-e -- 翻译表,翻译表是通过 maketrans() 方法转换而来。

detrletechars -- 字符串中要过滤的字符列表。

返回值

返回翻译后an的字符串,若给出了 delete 参数,则将原来的bytes中的sl属于delete的字符删除,剩下的字符要按照table中at给出的映射来进行映射 。

实例

以下实例展示了translate(e()函数的使用方法:

以上实例输出结果如下:

以下实例演示如何)方过滤掉的字符 o:

输出结果为:

分享到: