A small way to output hexadecimal to Chinese when the Python list contains Chinese

Source: Internet
Author: User

Symptom: The Chinese in the list appears in hexadecimal after it is printed

>>> lt=[' Great god ', ' Zhzhgo ']>>> print lt[' \xb4\xf3\xc9\xf1 ', ' Zhzhgo ']>>>

First, it needs to be clear, this is not garbled, this is the Unicode string in memory form, Python output data in the command line interface, if not ASCII code, it will be output in 16 binary form.

How to make the printed results appear in Chinese? The solution is as follows:

#-*-coding:utf-8-*-lt=["Great God", ' zhzhgo ']str= ', '. Join (LT) #将列表转换为字符串print strprint type (str) lt=list (str) Print Ltprint Type (LT)

The printing results are as follows:

Great God, Zhzhgo

<type ' str ' >

[' \xe5 ', ' \xa4 ', ' \xa7 ', ' \xe7 ', ' \xa5 ', ' \x9e ', ', ', ' Z ', ' h ', ' Z ', ' h ', ' g ', ' O ']

<type ' list ' >


This article from "Today's efforts, tomorrow's success!" "Blog, be sure to keep this provenance http://zhzhgo.blog.51cto.com/10497096/1709429

A small way to output hexadecimal to Chinese when the Python list contains Chinese

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.