本文摘自php中文网,作者(*-*)浩,侵删。
python3默认编码为unicode,由str类型进行表示。二进制数据使用byte类型表示。
字符串通过编码转换成字节码,字节码通过解码成为字符串

encode:str --> bytes(推荐学习:Python视频教程)
decode:bytes --> str
实例python 3.0+
1 2 3 4 5 6 7 8 9 10 11 | 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' ))
|
输出结果如下:
阅读剩余部分
相关阅读 >>
Python怎么安装第三方库?
Python函数学习的注意要点
Python3列表的基础学习(附示例)
Python3.7怎么运行
Python怎么写有死循环的程序
在Python中如何移除字典中的 key
Python中dict是什么意思
Python后端开发学习什么
Python以太坊虚拟机实现py-evm的内容介绍
django 常用orm操作实例介绍
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python3默认使用什么编码