python 怎么把字符转换为unicode编码

如题所述

实现代码如下:
a
=
'abce'#
print
type(a)b
=
a.decode("ascii")#
print
type(b)c
=
a.decode("ascii").encode("utf-8")#
print
type(c)
在python中进行编码转换都是通过unicode作为中间值实现的。所以要先decode成unicode字符,然后再使用encode转换成utf-8编码的str。可以把注释取消了,看下转换过程中的类型。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答