阿神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.
Inpython3, only byte objects in unicode encoding format can become str
。
其他编码格式的是bytes
, such as: gbk, utf-8………………
str
.str
.encode(编码格式) --> bytes
就是从 unicode 转换成 指定编码格式 的bytes
en
bytes
is the bytes
converted from unicode to the specified bytes
.decode(编码格式) --> str
就是从 指定编码格式的bytes
转换成 unicode 的str
encoding format
bytes
.str
了,不必转成bytes
de
str
🎜 is to convert from bytes
in the specified 🎜encoding format🎜 to unicode str
🎜
🎜print('Hello') 🎜'Hello' is already 🎜, just output it directly. 🎜巴扎黑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"