字符编码与转码

  • 参考文章

http://www.cnblogs.com/luotianshuai/articles/5735051.html

ASCII:1个字节          UTF-8:存英文1个字节,中文是3个字节        Unicode:存中文2个字节

发展历程:

  • 转码过程

  • 转码的例子
#-*-coding:gbk -*-
'''
一般文件编码是什么,则什么是文件是什么编码;python默认是utf-8
'''
a = "你好!"#这个是Unicode编码,所以没有decode方法
print(a.encode("gbk"))
print(a.encode("utf-8"))
print(a.encode("utf-8").decode("utf-8"))
print(a.encode("utf-8").decode("utf-8").encode("gbk").decode("gbk"))

原文地址:https://www.cnblogs.com/cheng662540/p/7994586.html