python 输出含unicode的字符串
代码:print(title)a=title[2:-2]print(a)print('\u6551\u6551\u8fd9\u4e2a\u82b1\u5b63\u5973...
代码:
print(title)
a=title[2:-2]
print(a)
print('\u6551\u6551\u8fd9\u4e2a\u82b1\u5b63\u5973\u5b69')
结果:
['\u6551\u6551\u8fd9\u4e2a\u82b1\u5b63\u5973\u5b69']
\u6551\u6551\u8fd9\u4e2a\u82b1\u5b63\u5973\u5b69
救救这个花季女孩
请问:
如何实现print(a)输出的结果像最后一个print一样输出中文呢 展开
print(title)
a=title[2:-2]
print(a)
print('\u6551\u6551\u8fd9\u4e2a\u82b1\u5b63\u5973\u5b69')
结果:
['\u6551\u6551\u8fd9\u4e2a\u82b1\u5b63\u5973\u5b69']
\u6551\u6551\u8fd9\u4e2a\u82b1\u5b63\u5973\u5b69
救救这个花季女孩
请问:
如何实现print(a)输出的结果像最后一个print一样输出中文呢 展开
1个回答
展开全部
普通字符串可以用多种方式编码成Unicode字符串,具体要看你究竟选择了哪种编码:
unicodestring = u"Hello world"
# 将Unicode转化为普通Python字符串:"encode"
utf8string = unicodestring.encode("utf-8")
asciistring = unicodestring.encode("ascii")
isostring = unicodestring.encode("ISO-8859-1")
utf16string = unicodestring.encode("utf-16")
# 将普通Python字符串转化为Unicode:"decode"
plainstring1 = unicode(utf8string, "utf-8")
plainstring2 = unicode(asciistring, "ascii")
plainstring3 = unicode(isostring, "ISO-8859-1")
plainstring4 = unicode(utf16string, "utf-16")
assert plainstring1 == plainstring2 == plainstring3 == plainstring4
unicodestring = u"Hello world"
# 将Unicode转化为普通Python字符串:"encode"
utf8string = unicodestring.encode("utf-8")
asciistring = unicodestring.encode("ascii")
isostring = unicodestring.encode("ISO-8859-1")
utf16string = unicodestring.encode("utf-16")
# 将普通Python字符串转化为Unicode:"decode"
plainstring1 = unicode(utf8string, "utf-8")
plainstring2 = unicode(asciistring, "ascii")
plainstring3 = unicode(isostring, "ISO-8859-1")
plainstring4 = unicode(utf16string, "utf-16")
assert plainstring1 == plainstring2 == plainstring3 == plainstring4
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询