ITPub博客

首页 > IT职业 > IT职场 > python字符串怎么解码?

python字符串怎么解码?

IT职场 作者:wangsys 时间:2021-09-11 10:16:42 0 删除 编辑

python字符串解码的方法:

python中可以使用decode()方法对字符串进行解码。

python中可以使用encode()方法将字符串转换为bytes类型,此过程称为“编码”。

decode() 方法用于将 bytes 类型的二进制数据转换为 str 类型,这个过程也称为“解码”。

decode() 方法的语法格式如下:

bytes.decode([encoding="utf-8"][,errors="strict"])

示例:

#!/usr/bin/python
 
str = "this is string example....wow!!!";
str = str.encode('base64','strict');
 
print "Encoded String: " + str;
print "Decoded String: " + str.decode('base64','strict')

输出结果如下:

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

Decoded String: this is string example....wow!!!

更多Python知识请关注Python自学网。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3244/viewspace-2833622/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-06

  • 博文量
    94
  • 访问量
    7080