Data stored on the hard disk, the hard disk can store binary
Binary - "Decimal -" ascii / gbk / utf-8 / unicode
Data stored to the hard disk, will be converted to a corresponding binary coding after storage,
Text - "utf-8 / gbk -" 2 hex
Picture - "jpg / png -" 2 hex
Music - "MP3 / wav -" 2 hex
Video - "MP4 / mov -" 2 hex
1 s = "小圆圈" 2 print(s.encode("utf-8")) 3 print(s.encode("gbk")) 4 5 6 b'\xe5\xb0\x8f\xe5\x9c\x86\xe5\x9c\x88' 7 b'\xd0\xa1\xd4\xb2\xc8\xa6'
bytes type to 2 constituting a hexadecimal byte (byte) to b '' is identified, byte strings
Py3 default encoding is utf-8 file
pycharm loaded by default files are encoded with utf- 8
. 1 F = Open ( " bytes.txt " , " W " , encoding = " UTF-. 8 " ) Finally, what can keep their encoded
Open the file in binary mode
1 f = open("bytes.txt","wb")
1. Character deposit hard to turn bytes
2. Network transmission of characters to become bytes