What encoding does python3 use by default?

(*-*)浩
Release: 2019-07-09 10:12:05
Original
16050 people have browsed it

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'))
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!