谈笑有鸿儒网

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

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

描述

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

语法

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

str.translate(table)

bPyytes.translate(table[, delete]) &nthbsp;  

bytearray.translate(tabonle[, delete]) 

参数

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

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

返回值

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

实例

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

以上实例输出结果如下:

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

输出结果为:

访客,请您发表评论:

© 2026. sitemap