Home  >  Article  >  Backend Development  >  What encoding does python3 use by default?

What encoding does python3 use by default?

(*-*)浩
(*-*)浩Original
2019-06-27 10:01:2816063browse

Python3 default encoding is unicode, represented by str type. Binary data is represented using the byte type.

The string is converted into bytecode through encoding, and the bytecode is converted into string through decoding

What encoding does python3 use by default?

encode: str --> bytes (recommended learning: Python video tutorial)

decode: bytes --> str

Example python 3.0

str = "我是Python3"
str_utf8 = str.encode('utf-8')
str_gbk = str.encode('GBK')

print(str)

print("UTF-8 编码:", str_utf8)
print("GBK 编码:",str_gbk)

print("UTF-8 解码:", str_utf8.decode('utf-8'))
print("GBK解码:",str_gbk.decode('GBK'))

The output results are as follows:

我是Python3
UTF-8 编码: b'\xe6\x88\x91\xe6\x98\xafPython3'GBK 编码: b'\xce\xd2\xca\xc7Python3'UTF-8 解码: 我是Python3
GBK解码: 我是Python3

The default encoding of python3 is unicode, utf-8 can be regarded as an extension set of unicode

encode: Indicate to use encoding, decode: indicates the encoding format of the current encoding

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What encoding does python3 use by default?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn