云计算开发:Python3-translate()方法详解
热点
2026-11-14
0
描述
Python translate() 方法根据参数tab云计le给出的表(包含 256 个字符)转换字符串的字符,要过滤掉的字符放算开到 deletechars 参数中。
语法
以下是 translate(发:) 方法语法:
str.translate(table)
byPytes.translate(table[, delete]th)
bytearray.translateon(table[, delete])
参数
table -3-- 翻译表,翻译表是通过 maketrans() 方法转换而来。
deletrtechars -- 字符串中要过滤的字符列表。
返回值
返回翻译后的字an符串,若给出了 delete 参数,则将原来的bytes中的属于delslete的字符删除,剩下的字符要按照table中给出的映射来进行映射at 。
实例
以下实例展示了translate()函数的使用方法e(:
以上实例输出结果如下:
以下实例演示如何过滤掉的字符 o:
输出结)方果为: