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




