Python中decode函数怎么用

873
2021/2/9 16:02:20
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: python安装后怎么更改路径