The default encoding in python3 is utf-8. In terms of storage and display, python3 uses text characters and binary data to distinguish, which is more clear and clear.
By default, Python 3 source files are encoded in UTF-8, and all strings are unicode strings. (Recommended learning: Python video tutorial)
Of course you can also specify different encodings for the source code file:
# -*- coding: cp-1252 -*-
Text characters are represented by the str type, and str can represent Unicode All characters in the character set, and binary data is represented by the bytes type.
Conversion between str and bytes
# bytes object b = b"example" # str object s = "example" # str to bytes bytes(s, encoding = "utf8") # bytes to str str(b, encoding = "utf-8")
Uses utf-8 by default
# bytes object b = b"example" # str object s = "example" # an alternative method # str to bytes str.encode(s) # bytes to str bytes.decode(b)
For more Python related technical articles, please visit the Python Tutorial column Get studying!
The above is the detailed content of What encoding is used in python3. For more information, please follow other related articles on the PHP Chinese website!