释放双眼,带上耳机,听听看~!
知识补充: python里的字符串有byte型和str型,有时操作数类型和操作类型不匹配就会报错 b64decode()结果是byte型字符串,而split()函数要为str型字符串 repr()函数可以将byte型字符串转换成str型字符串 另外,还有一个简单的方法: 1、byte型转str型 _str=_byte.decode() 2、str型转byte型 _byte=_str.encode() """ """ 知识点 import base64 st = 'hello world!'.encode() #默认以utf8编码 res = base64.b64encode(st) print(res.decode()) #默认以utf8解码 res = base64.b64decode(res) print(res.decode()) #默认以utf8解码 输出 aGVsbG8gd29ybGQh hello world! """ """ split() 通过指定分隔符对字符串进行切片,如果第二个参数 num 有指定值,则分割为 num+1 个子字符串。 实例 以下实例展示了 split() 函数的使用方法: str = "this is string example....wow!!!" print (str.split( )) # 以空格为分隔符 print (str.split('i',1)) # 以 i 为分隔符 print (str.split('w')) # 以 w 为分隔符 以上实例输出结果如下: ['this', 'is', 'string', 'example....wow!!!'] ['th', 's is string example....wow!!!'] ['this is string example....', 'o', '!!!'] 以下实例以 * 号为分隔符,指定第二个参数为 1,返回两个参数列表。 txt = "Google*Runoob*Taobao*Facebook" * 第二个参数为 1,返回两个参数列表 x = txt.split("*", 1) print(x) 以上实例输出结果如下: ['Google', 'Runoob*Taobao*Facebook'] ———————————————— 版权声明:本文为CSDN博主「彬彬有礼am_03」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/am_03/article/details/119958750