功能:
translate() 方法根据参数tab给出的表来转换对应的字符串的字符,也可以指定需要过滤的字符。
语法:str.translate(tab,[delete])相关参数:
str:需要进行转换的源字符串;
tab:映射表,就是定义需要用什么字符替换什么字符;
delete:可选参数,默认为空,需要过滤的字符串。
返回值:
返回替换后过滤后的新字符串。
注意事项:
1、其余字符串方法见:http://www.mihuguan.com/article/15703730746.html
实例说明:
>>>str1 = "hello" >>>str2 = "12345" >>>str3= str.maketrans(str1, str2) >>>str = "wo haha" >>>print (str.translate(str3)) w5 1a1a
jQuery2021-01-08
jQuery2021-01-07
MySQL2020-12-13
电脑2020-12-12
服务器2020-12-06
电脑2020-10-06