Python中decode函数怎么用 python中decode函数的用法

主机教程 建站分享 2年前 (2022-09-10) 176次浏览

文章摘要:Python中decode函数怎么用 python中decode函数的用法

在Python中使用decode函数的方法 decode:decode()函数的作用是指定的编码格式解码字符串 […]

在Python中使用decode函数的方法

decode:decode()函数的作用是指定的编码格式解码字符串。

decode()函数语法:

str.decode(encoding='UTF-8',errors='strict')

参数:

encoding:表示需要指定的编码。

errors:设置不同错误的处理方案。

decode()函数使用方法:

str = "hello world";

str = str.encode('base64','strict');

print "Encoded String: " + str;

print "Decoded String: " + str.decode('base64','strict')

输出结果为:

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=

Decoded String: hello world


声明:
若非注明,本站文章源于互联网收集整理和网友分享发布,如有侵权,请联系站长处理。
文章名称:Python中decode函数怎么用 python中decode函数的用法
文章链接:https://www.7966.org/post/14804.html
转载请注明出处

喜欢 (0)