search

Home  >  Q&A  >  body text

python - Why is there no garbled Chinese in the normal output? After the zip function, there is a problem with Chinese programming unicode encoding. I traverse the output.

阿神阿神2713 days ago961

reply all(1)I'll reply

  • typecho

    typecho2017-06-12 09:25:09

    Because zip combines every two independent strings into a tuple, and Chinese in tuples, lists, etc. data structures are stored according to unicode or hex , so what you see will be this result, which does not affect the use, nor is it garbled, because by directly traversing it and printing out the elements separately, you can see the content that can be recognized by humans. You can use the following code to help understand:

    # coding: utf8
    a = u'你好'
    print a          # 独立打印
    
    s = []           # 创建列表, 并存入列表
    s.append(a)   
    print s          # 将整个列表打印, 看到unicode编码存储的内容
    print s[0]       # 将元素单独打印, 看到正常的内容
    
    #### 输出  ###
    你好
    [u'\u4f60\u597d']
    你好

    reply
    0
  • Cancelreply