Home  >  Q&A  >  body text

ide - python3编码问题

PHP中文网PHP中文网2741 days ago357

reply all(2)I'll reply

  • 阿神

    阿神2017-04-18 09:39:33

    Python3 is improved to avoid encoding format confusion. By default, it reads and writes files in UTF-8 encoding format. There is no need to specifically specify utf-8.

    In

    python3, only byte objects in unicode encoding format can become str
    其他编码格式的是bytes, such as: gbk, utf-8………………

    str.str.encode(编码格式) --> bytes
    就是从 unicode 转换成 指定编码格式bytesen

    code (encoding format) --> bytes

    is the bytes converted from unicode to the specified bytes.decode(编码格式) --> str
    就是从 指定编码格式bytes 转换成 unicode 的strencoding format


    bytes.str了,不必转成bytesde

    code (encoding format) --> str 🎜 is to convert from bytes in the specified 🎜encoding format🎜 to unicode str 🎜 🎜print('Hello') 🎜'Hello' is already 🎜, just output it directly. 🎜

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:39:33

    There are only unicode encoding and str in python3. Encode is to encode the string into unicode (that is what you see and think is strange), and decode is to decode the unicode encoding into a string. Print just accepts a string directly. Use print('Hello') to output "Hello"

    reply
    0
  • Cancelreply