#!/user/bin env python
# author:Simple-Sir
# time:20180922
#指定當前文件編碼格式化:#-*- coding:utf-8 -*-
# unicode(萬國碼): 英文字母 1個字節,中文3個字節
#打印系統默認編碼
import sys
print(sys.getdefaultencoding())
# unicode encode --> utf-8/gbk
# utf-8/gbk decode --> unicode
# 將utf-8轉成gbk
s = '你好' #python中全部的字符都是unicode編碼,因此,此處s是unicode編碼
#unicode轉gbk
s_to_gbk = s.encode('gbk')
print('unicode轉gbk:',s_to_gbk)
#gbk轉unicode
gbk_to_unicode = s_to_gbk.decode('gbk')
print('gbk轉unicode:',gbk_to_unicode)
#unicode轉utf-8
gbk_to_utf8 = gbk_to_unicode.encode('utf-8')
print('gbk轉utf8:',gbk_to_utf8)