a、将字符串转换成utf-8编码的字节,并输出,然后将该字节在转换成utf-8编码字符串,在输出
b、将字符串转换后才能gbk编码的字节,并输出,然后将该字节在转换成gbk编码字符串,在输出
1
2
3
4
5
6
7
8
9
10
11
12
|
def
main():
n
=
"老男孩"
nBytes_utf
=
n.encode(
'utf-8'
)
nStr_utf
=
nBytes_utf.decode(
'utf-8'
)
print
(nBytes_utf)
print
(nStr_utf)
nBytes_gbk
=
n.encode(
'gbk'
)
nStr_gbk
=
nBytes_gbk.decode(
'gbk'
)
print
(nBytes_gbk)
print
(nStr_gbk)
if
__name__
=
=
'__main__'
:
main()
|
本文转自 yuri_cto 51CTO博客,原文链接:http://blog.51cto.com/laobaiv1/2066970,如需转载请自行联系原作者