默许情况下,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中运用什么编码的细致内容,更多请关注ki4网别的相干文章!