python3中使用什么编码
默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串。(推荐学习:Python视频教程)
当然你也可以为源码文件指定不同的编码:
# -*- coding: cp-1252 -*-
文本字符使用str类型表示,str 能表示 Unicode 字符集中所有字符,而二进制数据使用bytes类型表示。
str与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")
默认使用utf-8
# bytes object b = b"example" # str object s = "example" # an alternative method # str to bytes str.encode(s) # bytes to str bytes.decode(b)
更多Python相关技术文章,请访问Python教程栏目进行学习!
以上就是python3中使用什么编码的详细内容,更多请关注教程集其它相关文章!
您可能感兴趣的文章:
2019年python学3还是2
python3中使用什么编码
在python3.x中可以使用中文作为变量名吗
python u是什么意思
讲解Python3内置模块之json编码解码方法
python six模块是什么
Python3中默认编码是什么?怎么用?
python3怎么输出中文
一文了解Python虚拟环境
python2和3print的区别