第16課 python 編碼和文件讀寫

編碼
0,1
2進制 ,8 ,16進制;python

ACSII 是 127個  不到1個byte = 8bit

 因爲時間發現 歐洲 使用 第8個bit ,有256個字符,到了中國不足夠。因此中國人gb2312, gbk開發。。

 爲了python 程序方便。。。不能說python ,世界和平,規定了unicode (在內存運營)

 unicode 不人性化, 什麼都要佔 2個byte 16個bit,而後utf-8出現了機會。。。。中文3個byte,英文1個byte..

 #####################
 "aaa".encode("utf-8")

 a="aaa".encode("utf-8")
 a.decode("utf-8")

 b' xxxxxxxxxxxx' b 是說明bytes類型
 \x 跟 URL的 % 同樣用於分割而已。。。

 decode encode相互轉換。。。。。。。。。

 ##############################################
 file 操做
 open("a.txt","rwb",encoding="utf-8")

 根據本身需求選擇 r 讀;w寫;b 2進制的python3已經明確分類。

 ###############################################
 split()
 join()
 函數主要字符串組合,分離用得上。
相關文章
相關標籤/搜索