1 a = " "
2 print(bin(ord(a.encode()))) # 0b100000 # 最前面的10個0去掉
3 print(bin(ord(a))) # 0b100000
4 print(ord(a)) # 32
5 a = "~"
6 print(bin(ord(a.encode()))) # 0b1111110 # 最前面的9個0去掉
7 print(bin(ord(a)))
8 print(ord(a)) # 126
9
10 a = "ab"
11 print(a.encode()) # b'ab' # bytes
12 a = str("ab")
13 print(a.encode()) # b'ab' # bytes 其二進制表示能夠查ascii表
14 a = "我"
15 print(a.encode()) # b'\xe6\x88\x91'
16 print(ord(a)) # 25105 # """ Return the Unicode code point for a one-character string. """
17 print(bin(ord(a))) # 0b 1100010 00010001
18 print(bin(25105)) # 0b 1100010 00010001 # 返回的應該是unicode編碼 ,最前面的一個0去掉了0b 01100010 00010001
19 for i in a.encode():
20 print(i) # 230 136 145
21 print(bin(i)) # 0b11100110 0b10001000 0b10010001 則unicode編碼爲 0110 001000 010001
22
23 a = "我"
24 print(a.encode(encoding='gbk')) # b'\xce\xd2'
25
31
32 print("我".encode("gbk")) # b'\xce\xd2'
33 for i in "我".encode(encoding='gbk'):
34 print(i) # 206 210
35 print(bin(i)) # 0b11001110 0b11010010
36
37 print("######")
38 print("我".encode("gb2312")) # b'\xce\xd2'
39 for i in "我".encode("gb2312"):
40 print(i) # 206 210
41 print(bin(i)) # 0b11001110 0b11010010
42
43 print("#############")
44 # print(str("我".encode().decode()))