python字符串怎么解码?
发布时间:2026-03-24 19:52:15

python字符串解码方法:
decode()法可用于python中解码字符串。
encode()法可用于python将字符串转换为bytes类型,这个过程称为“编码”。
decode() 方法用于将 bytes 二进制数据转换为二进制数据 str 类型,这个过程也叫“解码”。
decode() 语法格式如下:
bytes.decode([encoding="utf-8"][,errors="strict"])
示例:
#!/usr/bin/python
str="thisisstringexample...wow!!!";
str=str.encode('base64','strict');
print"EncodedString:"+str;
print"DecodedString:"+str.decode('base64','strict')输出结果如下:
Encoded String: BzdHJpbmcgZXhbXBsZS4uLi53b3chISGhpcyBzdGhpcy=
Decoded String: this is string example...wow!!!
请关注Python自学网了解更多Python知识。
下一篇 返回列表
