温馨提示×

Python中decode函数怎么用

九三
358
2021-02-09 16:02:20
栏目: 编程语言

Python中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

0