python3.5 Str类型与bytes类型转换

 

 1 #str与byte转换
 2 a = "李璐"
 3 b = bytes(a,encoding="utf-8")
 4 print(b)
 5 c = bytes(a,encoding="gbk")
 6 print(c)
 7 d = str(b,encoding="utf-8")
 8 print(d)
 9 e = str(c,encoding="gbk")
10 print(e)
11 
12 for i in a:
13     print(i)
14     byte_list = bytes(i,encoding='utf-8')
15     print(byte_list)
16     for b in byte_list:
17 #bin()转换为二进制
18         print(b,bin(b))