• 技术文章 >常见问题 >Python常见问题

    python字符串怎么解码?

    yangyang2020-05-16 15:25:15原创3401

    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自学网

    专题推荐:python
    品易云
    上一篇:Python中val()是什么意思? 下一篇:python中脚本怎么执行sql语句?

    相关文章推荐

    • VS2013中怎么编写python?• VS2013如何配置Python环境?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网